Having Trouble with Lists and Functions fizz_count


#1

I can't figure out why I'm getting an error every time. It's telling me that I am returning the wrong number of "fizz" 's and it seems to think I have a list in there somewhere. The strange thing is the error message changes every time and tells me a different number of "fizz" 's that are in the list. Here is my code, this is step 4. in unit 5, a day at the supermarket.

def fizz_count(x):
    count = 0
    for item in x:
        if item == "fizz":
            count = count + 1
        return count

Error Message : Oops, try again. fizz_count([4, 'fizz', 7]) returned 0 instead of the correct answer: 1

If anyone has similar problems or knows whats going on please let me know,

Thanks!


#2

After doing a courtesy edit of your post, we can see the problem has to do with indentation. The return statement should be preceded by four spaces, not eight, so that it lines up with the for, not the if.