我的用户名/密码检查代码有什么问题?

时间:2019-04-04 18:44:57

标签: python-3.x

我是python的新手。目前,我正在通过编写代码来检查#输入的用户名和密码是否正确和匹配,以进行练习。我遇到错误后又遇到问题了。

complete = False


#List of Lists

adminList = [
    ["DaBigBoss","DaBest"],

    ["root","toor" ]
        ]

def checkLogin():
    userInfo = [

]    

username = input("What is your username?   ")
password = input("What is your password?   ")


if username == adminList[n][0]:
    True

elif password == adminList[n][1]:
    complete = True
    print("- Successfully Logged In -")


else:
    complete = False
    PromtLogin()

def PromtLogin():
    while complete == False():
        print("Please try again")
        checkLogin()



checkLogin()

当前这是错误输出

File "c:/Users/TJ/Desktop/Instructions/Resources/UserAdmin.py", line 44, in #<module>
  checkLogin()

File "c:/Users/TJ/Desktop/Instructions/Resources/UserAdmin.py", line 24, in checkLogin
  if username == adminList[n][0]:
NameError: name 'n' is not defined

1 个答案:

答案 0 :(得分:0)

您的代码中任何地方都没有定义名为n的变量

尝试一下:

# take username & password input
for admin in adminList:
    if given_user == admin[0] && given_password == admin[1]:
        # log the user in