[Tutor] (no subject)

Peter Otten __peter__ at web.de
Fri Nov 22 09:57:46 CET 2013


久場海人 wrote:

> Hi. I began programming literally 2 days ago.
> 
> This is a code to setup password and confirms to make sure they both
> match, and I need to know what coding I can use to loop back to specific
> line to start the code over if the user were to incorrectly typed in the
> password.
> 
> 
> 1. CreatePassword = raw_input ("Create New Password: ")
> 2. ConfirmationPass = raw_input ("    Retype Password: ")
> 3.
> 4.
> 5. if CreatePassword == ConfirmationPass:
> 6.     print ("Password Set!")
> 7. else:
> 8.     print ("Password did not match!")

Use an infinite loop and break out of that when you get the correct data. 
Example:

while True: # infinite loop
    guess = raw_input("Guess my number: ")
    if guess == "42":
        print "correct"
        break # break out of the infinite loop
    else:
        print "try again"



More information about the Tutor mailing list