[Tutor] Re: need help

Andrei project5 at redrival.net
Fri Sep 12 00:14:06 EDT 2003


valeri wrote:

Hi Valeri,

> Hi I am new to Python and programming, but I like it since I've tried 
> Python. I have difficulties using commande' else'
> after 'if' argument I try to enter 'else' and it gives me an arror 
> message. I am using Python 2.2, Live wires and pygame for beginners. 
> Please give me an advise or a link.

Shot in the dark here since you didn't provide the problem code, but this is how 
you *should* use the if/else:

if CONDITION: # CONDITION is an expression evaluating to True or False
     DO_SOMETHING # some statements executed if CONDITION evaluates to True
else:
     DO_SOMETHING_ELSE

Pay attention to the indentation and the colons. A less abstract example:

username = raw_input("Your name: ")
if username == "Valeri":
     print username, "has a question about if/else"
     # do more stuff
else:
     print username, "is an unknown user"

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq gur 
yvfg, fb gurer'f ab arrq gb PP.





More information about the Tutor mailing list