[Tutor] need help

Alan Gauld alan.gauld at blueyonder.co.uk
Fri Sep 12 15:45:52 EDT 2003


Hi Valeri,

> Thank you for helping me out. Here is what I enter in my Python
IDLE on
> windows xp home edition using livewires 2.0 tutorial pack:
> >> if 1 < 2:
>      print 'Something is wrong!'
>      else:

The else should be under the if not under the print.
The indentation is all important in Python.
BUT there is an extra problem which is a "feature"(Or bug!)
in IDLE:

>>> if 1<2:
       print 'foo'
else:
   print 'bar'

Notice the else has to go right back at the edge because thats
where IDLE thinks the if is located. Its only the >>> prompt
that makes it look further in.

If you start python in a DOS box (Go to Start->Run and type python)
you will find it looks like this:

>>> if 1<2:
...   print 'foo'
... else:
...   print 'bar'
...
foo
>>>

Note the way it inserts three dots so that everything lines up
properly? Unfortunately IDLE doesn't do that!

HTH,

Alan G.




More information about the Tutor mailing list