Lists + functions not looping


At any list the program inputs, my code always returns 1. It is like the "for" loop is not working.


Oops, try again. fizz_count(['fizz', 'fizz', 'fizz', 9, 'buzz', 9, 'fizz', 'buzz']) returned 1 instead of the correct answer: 4

def fizz_count(x):
    count = 0
    for item in x:               # indent 4 spaces
        if item == "fizz":       # indent 4 more spaces
            count = count +1     # indent 4 more spaces
        return count


a function ends the moment a return keyword is reached

if the return keyword is reached in a loop, the loop breaks, the function ends


Then? xD
Where do I place the return thing?


outside the loop, given the whole loop needs to run to find all instances of fizz


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