尽管输入了正确的信息,程序始终求助于"wrong login"



我在我的代码中没有看到任何缺陷,总是使用输出"登录错误&";。

credentials = {
"username1": "password1",
"username2": "password2"
}
while True:
useroutput = input("Type in your username: ")
passoutput = input("Type in your password: ")
if useroutput in credentials.keys() and not(passoutput in credentials.keys()) and passoutput in credentials:
print("Welcome back "+useroutput+"!")
break
else:
print("Wrong login!")
continue

这会检查用户名是否已知,然后检查密码是否分配给用户名

credentials = {
"username1": "password1",
"username2": "password2"
}
while True:
useroutput = input("Type in your username: ")
passoutput = input("Type in your password: ")
if useroutput in credentials:
if credentials[useroutput] == passoutput:
print("Welcome back "+useroutput+"!")
break
print("Wrong login!")

您的条件不起作用,因为此部件

not(passoutput in credentials.keys()) and passoutput in credentials

将始终是CCD_ 1。passoutput in credentials将检查钥匙。我想你想要passoutput in credentials.values()。即使这"会"起作用,每个用户都可以使用字典中的每个密码登录。

相关内容

最新更新