I need help figuring out how to fix this code.
Jaime Wyant
programmer.py at gmail.com
Tue Jun 28 14:46:27 EDT 2005
On 6/28/05, Nathan Pinno <falcon3166 at hotmail.com> wrote:
> Hi all,
>
[snip!]
It looks like your indentation is off for the if statement. It should
be aligned with the "name = raw_input" statement above it.
Also, elif name == ["Madonna", "Cher"]: will never evaluate to true.
Assume someone enters "guido" for their name, then you're doing this
comparison.
"guido" == ["Madonna", "Cher"]
A string will never equal a list. Now, a string could be in a list.
if name in ("Madonna", "Cher"):
print "Sorry, you can't come in."
hth,
jw
> #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!"
>
> What's wrong with the code? How do I fix it, so that it works?
>
> Thanks,
> Nathan Pinno
> http://www.npinnowebsite.ca/
>
More information about the Python-list
mailing list