Having Problems with my code


#1

def fizz_count(x):
count=0
for item in x:
if “fizz” == item:
count= count + 1
return count
a_list = [“fizz”, “cat”, “fizz”]
print fizz_count(a_list)

That is my code and it output 1, when it should output two. The lesson(4/13) was asking me to create a program that counted the number of time fizz appears in the list. Please Help?


#2

Check that the return is outside of the loop. It may have too much indentation.

for ...
    if ...
return ...

#3

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