有人可以查看此代码吗?其中大部分都在工作,但当他们输入'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? ")
答案 0 :(得分:9)
您需要将第一条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? ")
这确保密码首次出现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
答案 1 :(得分:2)
您需要在while循环开始之前放置password = ("Python")
。