[Tutor] Problem with "elif"
alan.gauld@bt.com
alan.gauld@bt.com
Sun, 25 Nov 2001 22:52:11 -0000
> >>> 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)
This looks like you are using IDLE - coz there are no ... prompts.
In that case you should NOT have indented the elif - even tho it looks OK.
This is coz IDLE sees the initial 'if' as being at the beginning of the
line, so the elif must be too.
Personally I always feel this is a bug in the IDLE Shell, it should
line up visually, but sadly it doesn't. (At least in V0.6)
See my session below:
>>> y = 1900
>>> leap = 'no'
>>> if y % 400 == 0:
leap = 'y'
elif y % 100 == 0:
leap = 'n'
>>> leap
'n'
>>> y = 2000
>>> if y % 400 == 0:
leap = 'y'
elif y % 100 == 0:
leap = 'n'
>>> leap
'y'
Yes, I agree, this is a very confusing foible of IDLE.
Alan g.