Python uses indentation to define code blocks, you can indent code by any amount, but it must match exactly in order to be at the same level.
so this is fine:
if a==b :
if c==d :
x()
y()
z()
But this:
if a==b :
if c==d :
x()
y()
z()
Will give you an indentation error because the call to
y
is not "lined up" with either
if
so the system doesn't know what to do with it.
Now, your code looks fine, but ... tabs and spaces are likely to be the problem. Editors that use tabs indent to the same position, but if you mix spaces in as well then the compiler doesn't know how many spaces a tab is supposed to represent.
Check your editor: some allow "show marks" to indicate tabs differently from spaces, some allow you to replace tabs with spaces (I'd turn that one on if I was you).
This is just one of the reasons I don't use Python: it's not designed to produce good, reliable, maintainable code!