I need help figuring out how to fix this code.

Gregory Piñero gregpinero at gmail.com
Tue Jun 28 14:52:54 EDT 2005


Make sure that line with name=="Nathan" is not indented.  It's hard to
tell from the code there.

Also, I'm thinking that this won't work:
 if name == "Nathan":
         print "What a great name!"
 elif name == ["Madonna", "Cher"]:

because the variable name is a string and not a list.  You could try:
 elif name in ["Madonna", "Cher"]:

Greg




On 6/28/05, Nathan Pinno <falcon3166 at hotmail.com> wrote:
>   Hi all,
> 
>   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. 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!"
> 
>   What's wrong with the code? How do I fix it, so that it works?
> 
>   Thanks,
>   Nathan Pinno
>   http://www.npinnowebsite.ca/ 
> 
> 
> 
> --
> 
> 
> ----------------------------------------------------------------
>      Posted via UsenetRevolution.com - Revolutionary Usenet
> ** HIGH RETENTION ** Specializing in Large Binaries Downloads **
>                  http://www.UsenetRevolution.com 
> --
> http://mail.python.org/mailman/listinfo/python-list 
>



More information about the Python-list mailing list