[Tutor] Just a Python formatting question

Alberto Troiano albertito_g at hotmail.com
Thu Jun 9 15:21:40 CEST 2005


Kristiano

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

>number=78
>guess=0
>
>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:
    do_something
    do_something_else
    if x==y:
        inside the if clause
        all statements go
        with 4 spaces after the if line
    elif x>y:
        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

Best Regards

Alberto
>
>  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.
>
>Thanks.
>-Kristiano Ang
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor


Gaucho




More information about the Tutor mailing list