[Tutor] Interactive programming.
Sander Sweers
sander.sweers at gmail.com
Tue Jan 6 21:16:41 CET 2009
On Tue, Jan 6, 2009 at 20:12, 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
Python uses indentation to seperate code blocks and will throw an
error if it finds inconsistancies. In your example else is indented
while it sould not be.
There is also a second error in the code. If you have an else you need
to do something in the else block. Below is a working version.
>>> i = 5
>>> j = 7
>>> if i <= j:
print 'Nudge nudge'
else:
print 'Icecream'
Nudge nudge
I know it looks weird in idle as the original if i <= j is to the
right of the else but both are *not* indented.
Greets
Sander
More information about the Tutor
mailing list