10.4 Cant figure out why my code isnt working


#1

Here is my code:

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

For some reason this isn't working for me... keeps returning either 0 or 1.. ?

and yes I have checked all my spacing. So confused right now

also too, "count += 1" doesn't work either :frowning:


#2

Just solved it. My Return line was indented one too many times haha


#3

Hi @devjumper48717 .

Glad you found the error. A common form of bug concerning a block of code, such as a function or a loop, is that a line of code is indented too little or too much. This makes it either external to the block when it should have been part of the block, or makes it part of the block when it should have been outside the block.

Because the code that you posted was not formatted, it was difficult for other users to read and debug it. After code has been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. This will enable us to see important details, such as the indentation and underscores.