I need help figuring out how to fix this code.
elmo13 at jippii.fi
Wed Jun 29 01:46:18 CEST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Nathan Pinno 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 "Program 3 - Loops and IF Conditions"
> 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!"
> print name,", that's a nice name!"
> What's wrong with the code? How do I fix it, so that it works?
> Nathan Pinno
I think about all the problems in your code are solved by suggestions
sent before me, but I have some advice for future situations:
Especially with more complex problems, larger code blocks using external
libs, etc, you should, if appropriate, include the Traceback, some
explanation on the given code(what it should do etc.) and maybe consider
documenting the code a little with comments and docstrings(try reading
some code you haven't seen before or in a long time, without any
commentation. What about debugging it without knowing what the code is
supposed to do?) Don't be intimidated by this, you just seemed to be new
with programming with python and thought of sharing this with you. You
have maybe read something like this before from a book or tutorial(there
are a couple of good free books for learning python, for example "byte
of python"), but good commenting and the like are usually appreciated
only when they're not available:)
Hope I didn't scare you. Happy tinkering with python!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the Python-list