这有什么不对吗? (蟒蛇)

时间:2015-01-24 14:58:10

标签: python python-3.x

    print ("*Default*")
    loop = 'true'
    while(loop == 'true'):
    username = input("Username Please  : ")
    passsword = input("Password Please  : ")
    if(username == "Default" and password == "Default2"):
    print ('Logged in Successfully as ') + username
    loop = 'false'
    loop1 = 'true'
    while(loop1 == 'true'):
        command = input(username + "{} > >")
        if(command == "exit" or command == "Exit"):
            break
        else:
            print ("'") + command + "' is not a valid command!"
    else:
        print ('Invalid Credentials!')

有人可以解释为什么这不起作用吗? 它说

line 6, in <module>
    if(username == "Default" and password == "Default2"):
NameError: name 'password' is not defined

1 个答案:

答案 0 :(得分:5)

您已将变量定义为passsword并将其作为password

进行访问
passsword = input("Password Please  : ")

这里

if(username == "Default" and password == "Default2"):

密码不是密码