Fizz Count - Indent Error


#1

https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/lists--functions?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
I am having an indentation error. Even though my counter seems to be located correctly, I keep getting the error below.

File “python”, line 5
count = count + 1
^
IndentationError: unindent does not match any outer indentation level

<What do you expect to happen instead?>
Ideally, there would be no error message and my fizz counter would return the number of fizz’s counted. When I print the count total, it prints the correct amount. But the function is not returning the correct number to the system. If one fizz appears, CodeAcademy says my function only counts 0, but my code will print 1 if I were to call for the function to print, as I did previously to check the logic.



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





#2

Hi @byteplayer91930,

Look at how:

is indented, it should be indented under our if statement. Since we’re checking if our item is equal to "fizz", then we want our reassignment to be indented below it because that’s what’s going to happen if this: (item == "fizz") is true. Does that make sense?


Also, check how our return keyword is placed; it shouldn’t be after our function, it should be in it. :slight_smile:


#3

Thank you for the quick reply!

if item == ‘fizz’:
count = count + 1

I have the if indented underneath the for loop. And the count is underneath the if statement. I have 4 spaces for each indent
:frowning_face:


#4

Try to unindent all of your code like so:

def fizz_count(x): #see how everything is unindented?
count = 0
for item in x:
if item == 'fizz':
count = count + 1 
return count

Then indent your code using 4-space indentation (by pressing the space-bar 4 times) instead of 2-spaces. Do you know what I mean?


#5

OH MY GOSH!

That worked!!! I’ve been trying to get around this error message for 3 days, thank you sooooooo much!! Lol that’s all it took, thanks so much!!


#6

Yep, you’re welcome :grinning:


#7

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