[Tutor] i have a question

Andrei project5 at redrival.net
Sun Mar 12 12:11:18 CET 2006


Tom Bachik <beamer30 <at> gmail.com> writes:

> ok say u want python to ask the user to type a username then password for a
game account thats easy but how do u get the information they typed back to you?

Depends on the environment you're asking it in. If it's command-line, you're
probably using the raw_input function in order to get the name. This function
simply returns a string that you can use, so you could write something like:

  username = raw_input("Name: ")
  password = raw_input("Password: ")
  if CheckPassword(username, password):
      print "Hello %s" % username
  else:
      print "Incorrect name or password!"

Other environments (e.g. wxPython, PyGame or web interfaces) offer different
ways of achieving the same results, but I presume you're really new to Python
and not yet messing around with those.

Yours,

Andrei



More information about the Tutor mailing list