[Tutor] Interactive programming.

Alan Gauld alan.gauld at btinternet.com
Tue Jan 6 20:57:39 CET 2009

"WM." <wferguson1 at socal.rr.com> wrote
> >>> i = 5
> >>> j = 7
> >>> if i <= j:
> print 'nudge, nudge'
>           else:
>   File "<pyshell#8>", line 3
>     else:
>    ^
> IndentationError: unexpected indent
> Running in IDLE, all is well until "else:". IDLE seems perplexed

This is, in my view, a long standing bug in IDLE. It doesn't show 
properly in the shell window. If possible I'd suggest you try using 
or PyCrust or IPython or any of the other 3rd party shell windows.

If you use them they will typically insert three dots as a secondary 
which keeps everything lined up properly.

The else should align with the if but in Idle it has to align to the 
left margin
because the if is only indented due to >>> prompt! This is confusing,
and effectively a bug in my opinion. Your if statement in IDLE should 
look like:

>>> if i <= j:
    print 'nudge, nudge'

ie the print should be indented and the else not be.
Without the >>> it becomes sane:

if i <= j:
    print 'nudge, nudge'

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list