[Tutor] Problem with "elif"

dman dsh8290@rit.edu
Sat, 24 Nov 2001 17:30:56 -0500


On Sat, Nov 24, 2001 at 09:14:20PM +0100, Pjotr wrote:
| Hello!
| I started learning Python, using Python 2.1.1 and Ivan Van Laningham's
| book "Teach yoursefl Python...".  I have a problem with instruction
| "elif":
| >>> y = 1900
| >>> leap = "no"
| >>> if y % 400 == 0 :
|         leap = "yes"
|     elif y % 100 == 0 :
|             
| IndentationError: unindent does not match any outer indentation level (line 3)
| >>> 
| 
| What's up? This example is from Laningham's book and everything should
| be OK. Please help me!

I notice that in your cut-n-paste above, there is no prompt in front
of the lines following the 'if'.  Here is an example that works, and
that doesn't work, for me (python 2.1.1 also) :

>>> if 1 :
...     print "hello"
... elif 2 :
...     print "world"
... 
hello
>>> 


>>> if 1 :
...     print "hello"
...  elif 2 :
  File "<stdin>", line 3
    elif 2 :
           ^
IndentationError: unindent does not match any outer indentation level
>>> 



Notice that in the second example the 'e' in "elif" is not in the same
column as the 'i' in "if".  This is what the error message is trying
to say.

HTH,
-D