4/12 Right code, wrong results?



The error message says this, "fizz_count(['buzz', 'fizz', 'fizz', 'fIzZ', 'fizz', 'fizz']) returned 0 instead of the correct answer: 4".

I'm just confused because I looked at the example, directions, and other people's posts and they appear to be getting the question correct with the same exact answer. Any help would be appreciated.

def fizz_count(x):
    count = 0
    for i in x:
        if i == "fizz":
            count = count + 1
        return count
x = ["fizz","cat","fizz"]
fizz = fizz_count(x)
print fizz


a function ends the moment a return keyword is reached

If the return keyword is reached in a loop, the loop simply breaks


i don't understand. How do I stop this from happening?


By placing return outside the for loop


So it was an indentation error?


No, indention error is when you use inconsistent indention, for example:

def example():
   print "this is"
        print "an indention error"

your program was syntax wise correctly indented, the design/flow was just not right


Ah okay. I think I get it now. Thank you for your help.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.