What's wrong with my code?


I'm on #4 in this exercise.

When I run the code, I get error messages like this: "Oops, try again. fizz_count([7, 'buzz', 'fIzZ', 'fIzZ', 'fizz', 'fizz', 'fizz', 'fizz']) returned 0 instead of the correct answer: 4".

It's supposed to return the correct number of "fizz" strings in the list.

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


a function ends the moment a return keyword is reached

so your function ends in the first iteration/run of the loop

but to succesfully determine the number if fizzes in x, the whole loop needs to run


Oh, I see. My return function was in the loop itself, while it needed to be on the same level as the beginning of the loop to end it. Thanks for the quick help.


yes, this indention difference has quit an influence on how your program works :wink:


there is indententation error. currently return is in for loop