[Tutor] While Loop

Andrew Brunn abrunn1133 at yahoo.com
Wed Jun 13 07:29:32 CEST 2012


Let me preface by saying that I am currently taking my first programming
 class; so I have been a "programmer" for just over a week now.

Here is my question;

I
 am trying to create a while loop that will allow me ask for a username 
and password.  If a wrong username and password is entered, I would like
 the program to prompt the user to re-enter the username and password 
until they get it correct.  That means even if they get it wrong a 
thousand times, I want to program to keep asking them.

This is my code;

[code]
username = ""

while not username:
    username=raw_input("Username: ")
                       
password = ""

while not password:
   
 password=raw_input("Password: ")
if username == "john doe" and password == "fopwpo":
    print "Login successful"
else:
    print "Error. Please re-enter your username and password."
[code]



Andy Brunn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120612/bcb59649/attachment.html>


More information about the Tutor mailing list