Can someone check this code please? Most of it is working but when they type 'admin' it should allow them to set a new password 'type new password' but then the new password doent save. Can anyone help me fix it? Thanks
program = ("live")
while program == ("live"):
password = ("Python")
question = input("What is the password? ")
if question == password:
print ("well done")
if question == ("admin"):
n_password = input("What is the new password? ")
password = n_password
question = input("What is the password? ")
else:
question = input("What is the password? ")
You need to move the first password = ... line out of the loop:
program = ("live")
password = ("Python")
while program ==("live"):
question=input("What is the password? ")
if question == password:
print ("well done")
if question == ("admin"):
n_password = input("What is the new password? ")
password=n_password
question=input("What is the password? ")
else:
question=input("What is the password? ")
This ensures that the password is Python the first time around but after that it'll use the new value for password. Also note that you can remove a few input() calls:
program = ("live")
password = ("Python")
while program ==("live"):
question=input("What is the password? ")
if question == password:
print ("well done")
if question == ("admin"):
n_password = input("What is the new password? ")
password=n_password
You need to put password = ("Python") before the beginning of your while loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With