What's wrong with my code?


#1

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


#2

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


#3

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.


#4

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


#5

there is indententation error. currently return is in for loop


#6