+ 2

What does this error mean?

IndentationError: unindent does not match any outer indentation level

17th Oct 2019, 7:17 AM
Aaron Woodmore
Aaron Woodmore - avatar
6 Answers
+ 6
I have explained it in here (just read, don't run). https://code.sololearn.com/cT5BRIbkia21/?ref=app
17th Oct 2019, 7:37 AM
HonFu
HonFu - avatar
+ 5
python doesn't work with brackets but instead with indents. For example if you write an if you need to set everythin inside the if one tab to the right. inteligence = 1 if inteligence==1: print("I am smart!") else: print("I have small brian!") you can see that the prints aren't all the way to the left but instead moved more to the right. That different position acts like a bracket. If you want an if inside an if you need more position. if inteligence>1: print("I am smart!") if intelligence>2: print("Very Smart!") here the print inside the second if is even more to the right and therefore part of the second if but not directly part of the first if. You generate the correct indents with tab. Remember that they act like brackets so everything that isnt in the right position isnt part of the if you maybe want the command to be. Hope that helped. Good luck!
17th Oct 2019, 7:43 AM
Loris Thierry HĂŒtter
Loris Thierry HĂŒtter - avatar
+ 4
This is what I’m working on and where I experienced the error if it helps: https://code.sololearn.com/csfZ1SB59dy9/#py
17th Oct 2019, 7:46 AM
Aaron Woodmore
Aaron Woodmore - avatar
+ 4
Line 3 to 5 have to be indented 4 spaces.
17th Oct 2019, 7:57 AM
HonFu
HonFu - avatar
+ 3
Aymane Boukrouh, thanks! You're right, I should probably mention that issue. It seems to depend a bit on which environment you write in. I've copypasted code from Sololearn to Pydroid before; added a line, all looked fine - and suddenly indentation error.
17th Oct 2019, 11:29 AM
HonFu
HonFu - avatar
+ 1
HonFu you code was very helpful, I didn't actually know about line 31. But I think you forgot to mention one other thing, which is that tabs and spaces cannot be used in the same file.
17th Oct 2019, 10:20 AM
Aymane Boukrouh
Aymane Boukrouh - avatar