[Tutor] Just a Python formatting question
albertito_g at hotmail.com
Thu Jun 9 15:21:40 CEST 2005
Don't worry about it. I'm sure everyone passed over this before.
The identation errors are errors in the tabulation of a line
Let's take your code in example
>while guess != number:
> guess=input ("Guess a number:")
> if guess > number:
> print "Too High"
> elif guess < number:
> print "Too low"
The last line has to belong to the elif clause, right?
so if you are working with a single tab or 4 spaces (default identation in
Python) that means that for every loop statement, try , functions, classes
or any line that ends with ":", the next line has to be 4 spaces forward.
And all the lines that belong to the statement also. It does not matter if
is a nested sequence. Let me lighten you:
for i in somelist:
inside the if clause
all statements go
with 4 spaces after the if line
the same here
You ended an identation when you went back the spaces and typed elif so you
don't acumulate the identations, you just keep using 4 spaces after the line
with the ":" so Python knows what's inside and what's outside
I hope to be clear, and if you don't understand it (probably because of my
English) you can always read in the tutorial or in the Python help
> print "Just right"
>I just can't get it to run and I get some indentation error.
> I'm pretty new to this so I'm sorry if this question(s) sound(s)
>amateurish. Do help.
>Tutor maillist - Tutor at python.org
More information about the Tutor