Lesson 12: Stocking Out


Not sure what I’m doing wrong. Console indicates my indentation is off. If anyone can give me some advice that would be great :slight_smile:


Look at 24 of your code (return total)… that’s where the problem is. Basically, you need to indent that line of your code just a little bit. :slight_smile:


The console is very fussy about indentation, as it’s making you conform to the standard of two-space indentation coding standard that they laid out in “Whitespace Means Right Space”.

On Codecademy, we will use two-space indentation (two blank spaces for each indentation) to make sure you can easily read code with multiple indentations in your browser.

When you get this error, do this:

  1. look at the line of code that it’s telling you where the problem is. In your case, it’s on line 24.
  2. Put your cursor at the start of that line. In your case, put your cursor just before the r in return.
  3. Now backspace all the way to the left.
  4. Now using the space bar on your keyboard, press it 2x to get that line of code indented 2 whitespaces to the right.

Give that a try.


Thanks for the response. Hmmm…

So from as far left as it can be on the line:

(here is a screen shot just for visuals :slight_smile:)

then I hit the space bar twice (still getting an error) :confused: :


So working with line 24 I moved everything to the far left and then spacing twice to the right however I’m still getting an error :confused: the “return total” should be lined up with the for right? The indentation is what always gets me.


Hmm, have you tried refreshing the page. I’ve gotten this error many times (with correct indentation) and refreshing the page worked for me.

Also, have you noticed that the color of the return keyword is blue? I think that means that your indentation is lined up with one of the lines of your code (such as line 20 where your for-loop is). If it’s not lined up, then the color usually turns white.

If I’m wrong please correct me.


It’s being really fussy then and it might actually be the lines of code above it. Here’s a way to reset the indentation:

  1. For each line of code, backspace it to the line before. Start at the if, as it looks visually like more than 2 spaces.
  2. Then press return/enter on your keyboard. The editor will indent it for you.
  3. Repeat that for line 22 and 23.


I refreshed it but now it is saying my line 23 is wrong. Hmm maybe I’m missing something minor.


Odd… it looks fine. :thinking:

Study the error code. Python thinks we unindented this line of our code (line 23); have you tried what @hellofromtonya posted above?

Usually, when Python warns us about indentation/unindentation, we sometimes try to do the opposite of what the error said, so in your case, Python is telling us about unindentation, that means we can try to indent our code.


Let’s do this. Instead of showing me a picture, let’s look at your actual code, as the picture looks like 4 spaces and not 2.

  1. Click on the </> icon in the forum editor to create a code block.
  2. Copy and paste your code between the triple back ticks


Ah it finally worked! I reset all the lines and just did what you said. Thanks :smiley:


Thanks for the help :slight_smile: I finally was able to get it to work just by resetting all the lines.


Excellent. Good job. Now you are armed with what it takes the next time you get that same error. Cheers.


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