This error is caused when the actual indentation does not match the expected indentation -- a likely culprit is tabs v spaces, and indentation consistency.
For example, the following code would throw this error:
if true:
return 1
if false:
return 2
Note that while the true
statement is indented by 4 spaces, the false
statement is indented by five.
This example would also throw this error, and depending on your text editor could be invisible (hidden chars added for reference):
if true:
....return 1
if false:
⇥ return 2
In this case the true
statement is indented using four space characters, while the false
statement is indented using a tab symbol.
Along with the IndendtationError you provided, it should give you the exact line the error is occuring on. That said, the sample you provided is small enough that unindenting & reindenting the whole thing should resolve it.