[Tutor] If Elif

Anna Ravenscroft anna at aleax.it
Thu Feb 19 17:39:41 EST 2004


On Thursday 19 February 2004 05:05 pm, big steve wrote:
> I am having a problem getting the IF/ELIF to cooperate with me. I am using
> a sample from:      Learn to program  By Alan Gauld. I keep getting this
> msg:
>
> IndentationError: unindent does not match any outer indentation level
> (<pyshell#3>, line 3)
>
>
>   But When I don't indent I get:
>                                   SyntaxError: invalid syntax
> ___________________________________________________________________________
>______
>
> This is the sample I was trying:
>
> value = 100
> if value > 10:
>     print 'This is OK'
> elif value > 50:      #This is where I get that msg (IndentationError)
>     print "Whoops, this is never seen'
> else
>     print ' nor is this'

You're missing a full colon after else: 

I suspect that when you're typing this into your email that you're not typing 
it *exactly* as you are in your script. You need to use exact precision when 
typing. Are you using the IDLE window to edit your script or another text 
editor? If you're using another text editor, I'd try redoing it in the IDLE 
window and see how it works for you. Be very careful to type all the colons - 
they make a difference. Don't hit errant spaces or backspaces... If that 
doesn't work, try doing it by just entering the spaces yourself without 
relying on the "automagic" indentation. 

Once you've got it running, take a look at the logic to see how you could 
improve it. Hint - look at the order the conditions are evaluated... Right 
now, it would *always* print "this is OK" because the first clause is 
evaluated, comes up true, and it skips the rest of the clauses... 

Hope this helps give you a starting point.

Anna




More information about the Tutor mailing list