tha*_*l_1 3 python variables for-loop
有人可以检查一下这段代码吗?其中大部分都在工作,但当他们输入'admin'时,应该允许他们设置一个新密码'输入新密码',然后新密码保存.任何人都可以帮我修复它吗?谢谢
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? ")
Run Code Online (Sandbox Code Playgroud)
您需要将第一password = ...行移出循环:
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? ")
Run Code Online (Sandbox Code Playgroud)
这确保密码是Python第一次,但在此之后它将使用新值password.另请注意,您可以删除几个input()电话:
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
Run Code Online (Sandbox Code Playgroud)