[Tutor] if...

William Allison wallison1@sc.rr.com
Mon Nov 11 16:38:06 2002


Hi all,
I'm trying to learn Python with the "How to Think Like a Computer 
Scientist" book.  In chapter four, the if statement is introduced.

if x < y:
  print x, "is less than", y
elif x >  y:
  print x, "is greater than", y
else:
  print x, "and", y, "are equal"

I can't seem to get this to work at all.  If I line up the 'elif'  with 
the 'print' I get SyntaxError: invalid syntax from idle.  When I line up 
the 'elif' with the 'if' I get: IndentationError: unident does not match 
any outer indentation level (line 3).  However when I save it as 
iftest.py like this, it works as expected.

#!/usr/bin/python

x = 11
y = 11

if x < y:
	print x, "is less than", y
elif x > y:
	print x, " is greater than", y
else:
	print x, "and", y, "are equal


I'm using Debian GNU/Linux 3.0, python 2.1.3 and Idle 0.8.  Any ideas?
Thanks,
William