I need a bit of help


For some reason, I can't get my program to work

My code should be returning the value of 2 because "fizz" appears twice in the list, but instead, my program returns 1. How is this possible?

The program should return to

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

print fizz_count(["fizz","cat","fizz"])


return should be outside the for loop :slight_smile:

the function stops running after it reaches the return command, so after the for loop ran once, it reach "return" and the function stopped


thanks a lot. How did I not see that


No problem, just helping the community :slight_smile:


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