Inconsistancy in indentation

I’m on ex19 and when I run it in Power Shell it returns an ‘inconsistency in indentation’ error, and I looked it up in Bing and one person answered it by saying that Python sees ‘tabs’ and ‘spaces’ as being different. It says to go into your editor and click make ‘tabs into spaces’, but I’m sure I didn’t use tabs. I haven’t tried that yet, but since I didn’t use tabs, I doubt it would work. Most of what I have read about it is slightly over my head, (like up there with the International Space Station) and the book (LPTHW3) doesn’t help much. I have tried indenting 4 spaces, moving things over by adding a space here and there but nothing. Make it easy, because like my name, I’m Not2smart. Thank you.

Hello @Not2smart.
Nice to see you in here again.

It would be helpful if we could see your code.

Copy and paste into here. 

And which editor do you use when writing your code?

Looking forward to help you with this.

Change your name, man! And everything will go more smoothly :slight_smile:
Would you like Dwayne Johnson if he calls himself “The Pepple”? He is “The Rock” because he believes it and he lives it. Good luck.

… and show us your code! Everyone of us has such problems with code from time to time. It’s normal.

Line 3 is the problem, and it returns a caret and the very last parenthesis.

def cheese_and_crackers (cheese_count, boxes_of_crackers):
    print(f"You have {cheese_count} cheeses!")
	print(f"You have {boxes_of_crackers} boxes of crackers!")
	print("Man that's enough for a party!")
	print("Get a blanket,\n")
print ("We can just give the function numbers directly:")
cheese_and_crackers (20,30)
print("OR, we can use varibles from our script:")
amount_of_cheese = 10
amount_of_crackers = 50
print("We can even do math inside too:")
cheese_and_crackers(10+20, 5+6)
print("And we can combine the two, variables and math")
cheese_and_crackers(amount_of_cheese+100, amount_of_crackers)

I forgot that I should have said I’m using Notepad++.


I copy your code and tried myself.
When I removed the indentation and put back four spaces on line 3, 4 and 6 it worked fine.

I have a slight feeling there is only three spaces in your code.
But this can be something that happens when I copy from the forum and paste into my editor.
So I cannot say for sure this must be the reason

Hi @Not2smart you use tabs on line 3, 4 and 5 and there is one indentation to much:
Remove the tabs and it will work:


def cheese_and_crackers (cheese_count, boxes_of_crackers):
    print(f"You have {cheese_count} cheeses!")
    print(f"You have {boxes_of_crackers} boxes of crackers!")
    print("Man that's enough for a party!")
    print("Get a blanket,\n")

For some reason when I copied and pasted that code, it indented lines 3,4 and 5. So I went back to my Notepad++ and they are correct just like it is in the book. Before I wrote my first message, I moved the print statements around and counted off 4 spaces exactly on all lines. So that is not the problem. Although I’m sure I did not use tabs, I will see about using that setting that is supposed to be on Notebook++ and Idle that makes tabs into spaces. Thank you for your interest and help. Not2smart

I found a good post on stackoverflow how to convert tabs in spaces:

Maybe it helps.

1 Like

OK! I got it to work. I went to stackoverflow as DidierCh said to and read up on my version of Notepad++. I have 6.9.1. Anyway, I went to the setting in Notebook and changed tabs to spaces. I think that was part of the answer but when I ran it, it didn’t work. So I put the cursor on the side of every line (except line one) and hit the del key which brought the lines to the left margin. Then I hit the tab key and that put them back. Then when I ran it that worked. So to tell you the truth, I really don’t know what worked, but I learned something and will pay more attention to using tab or spaces in the future. Thanks all for your help. Not2smart.


This reply is brilliant @DidierCH, now @Not2smart be sure to set your text editor to always use spaces. It’s different in every one but every programmer’s editor has one.