Python Forum

Full Version: [split] Password Generator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, I've been trying to write this code that would tell me to stop once I entered the wrong password three times in a row and I don't know how to do it. Disclaimer, I'm very new to Python 3. I wrote the python code below for password input but it doesn't prompt me to stop after three attempts. What should I add to this code? or what should I delete so I can achieve what I wanted it to do. Just need some boost and help so I can clear my mind. (^^o) Can't seem to sleep at night when you don't get what you want to happen with your code. A bit of help is appreciated! Thanks!

password = str(input("Please enter password to continue: "))
if password == "fusion":
    print("Welcome! the password is correct, you may enter.")
    exit()

while password != "fusion":
	print("what is the Password?")
	password = input()

while password == "fusion":
	print("Welcome! the password is correct, you may enter.")
	exit()
Thank you,
Josh
Hi,
I'm a newbie too!. I've done something with my knowledge, please check whether it suits for you.


password=str(input("Enter the password:"))
if password=='fusion':
    
    print ("Welcome!the password is correct, you may enter.")
    exit()

while password!='fusion':
    i=0      
    while i<3:
        password=str(input("You have entered invalid password, please enter teh password again:"))
        if password=='fusion':
            print ("Welcome!the password is correct, you may enter.")
            exit()
        i+=1
    print ("You have reached the maximum limit")
    break
I know how to do this is Python 2. I'm pretty much a beginner as well. I'd do it like this:

password=raw_input("Enter the password: ")
times_wrong=0
while times_wrong<3:
if password=="fusion":
print "Welcome! The password is correct, you may enter."
break
else:
print "What is the password?"
times_wrong+=1

As I said before, I only know how to work Python 2. I suppose you'll be able to work out the syntax differences and stuff.