I need help figuring out how to fix this code.

Chinook chinook.nr at tds.net
Tue Jun 28 15:30:36 EDT 2005


On Tue, 28 Jun 2005 14:39:47 -0400, Nathan Pinno wrote
(in article <42c1997b$0$6975$b9fe7a78 at news.usenetrevolution.com>):

>   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/
> 
> 
> 
> 

At least one problem is further within the "if" >

Python 2.4.1 (#2, Mar 31 2005, 00:05:10) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)]
Type "help", "copyright", "credits" or "license" for more information.
>>> name = 'yosa'
>>> test = ['yosa', 'sosa']
>>> name == test
False
>>> name in test
True
>>> 

Lee C





More information about the Python-list mailing list