【发布时间】:2020-02-24 12:20:30
【问题描述】:
file = open("Login.txt","a")
file.write (newusername1)
file.write (",")
file.write (newpassword1)
file.write("\n")
file.close()
print("")
incorrect_credentials2=True
while incorrect_credentials2:
username1=input("Please enter your username: ")
password1=input("Please enter your password: ")
with open('Login.txt') as f:
if username1 +","+ password1 in f.read():
print("Logged In")
incorrect_credentials2 = False
else:
print("Incorrect username or password")
incorrect_credentials2 = True
当我删除不正确的_credentials2 位(循环)时,这段代码有效,但是当我拥有它时,它不会显示在外壳中。任何帮助将不胜感激
【问题讨论】:
-
请附上证明问题的minimal reproducible example,不要链接到外部网站
-
你的第二个 if 条件在 while 循环之外,你永远不会退出第一个 while 循环。所以你的代码卡在那里。检查下面我的答案以获取更正的代码。