How to change a variable within a program
for-loop, python, variables
Solution
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
Problem
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? ") ```