I need a bit of help


#1



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"])


#2

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


#3

thanks a lot. How did I not see that


#4

No problem, just helping the community :slight_smile:


#5

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