Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尽管输入了正确的信息,程序总是求助于“错误登录”_Python - Fatal编程技术网

Python 尽管输入了正确的信息,程序总是求助于“错误登录”

Python 尽管输入了正确的信息,程序总是求助于“错误登录”,python,Python,我看不到我的代码中有任何总是导致输出错误登录的缺陷 credentials = { "username1": "password1", "username2": "password2" } while True: useroutput = input("Type in your username: ") passoutput = input("Type i

我看不到我的代码中有任何总是导致输出错误登录的缺陷

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

永远都是假的。凭证中的passoutput将签入密钥。我想您希望在credentials.values中使用passoutput。即使这个“会”起作用,每个用户都可以使用字典中的每个密码登录。

如果条件没有意义,那么我完全可以理解,请详细说明为什么不在凭据中同时使用notpassoutput.key和passoutput凭据?这自相矛盾。