I need help figuring out how to fix this code.
harold fellermann
harold.fellermann at upf.edu
Tue Jun 28 14:56:13 EDT 2005
Hi,
> I need help figuring out how to fix my code. I'm using Python 2.2.3,
> and
> it keeps telling me invalid syntax in the if name == "Nathan" line.
The problem is that you indent the if statement. the if/elif/else
statements
are part of the outer block, so they do not need indentation.
> Here is the code if you need it.
> #This program asks for a password, then asks for the user's name
> after the
> correct password has been supplied. The computers response will vary,
> # depending on the name inputted.
> print "Program Author: Nathan Pinno"
> print "ID# 2413448"
> print
> print "Program 3 - Loops and IF Conditions"
> print
> password = raw_input("Type in the password, please: ")
> while password != "hello":
> print "Incorrect password!"
> print "Welcome to the second half of the program!"
> name = raw_input("What is your name, please? ")
> if name == "Nathan":
> print "What a great name!"
> elif name == ["Madonna", "Cher"]:
> print "May I have your autograph please!"
> else
> print name,", that's a nice name!"
name = raw_input("What is your name, plase? ")
if name == "Nathan" :
print "What a great name!"
elif name in ["Madonna","Cher"] : # in better than == here :)
print "May I have your autograph please!"
else : # don't forget the ":"
print name, ", thats a nice name!"
cheers,
- harold -
--
You can imagine the opposite
-- Maurizio Nannucci
More information about the Python-list
mailing list