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


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

``` def fizz_count(fi): fi = ["fizz","cat","fizz"] count = 0 for x in fi: if x == "fizz": count = count + 1 return count ```

Unfortunately, I am unable to execute the above codes and get desired output. Please someone verify and guide. Thanks a mill in advance.
I


#2

I found your problems:

fi = ["fizz","cat","fizz"]

This line is conflicting with the variable that fizz_count uses. This gives fizz_count a variable to count “fizz” with, so it won’t use whatever else would be given to it. Take out that line.

Also, the return count on line 7 need to be pushed back to be in line with for x in fi on line 4. I don’t know exactly why this is a problem, but my theory is when return commands are not in line with For x in y, they are included in the loop and return the incorrect value.


#3

Hello, Thanks for your reply.

Replaced the codes with the below and found it working

def fizz_count(fi):
count = 0
for item in fi:
if item == “fizz”:
count = count + 1
return count