Lists + functions not looping


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096#


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

ERROR:

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


#2

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


#3

Then? xD
Where do I place the return thing?


#4

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


#6

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