您好,我在这里有一个代码,其中有一个while循环用于密码功能。该功能正在起作用,当在
中键入正确的密码时,我只是无法结束循环# Administrator accounts list
adminList = [
{
"username": "DaBigBoss",
"password": "DaBest"
},
{
"username": "root",
"password": "toor"
}
]
# Build your login functions below
def getCreds():
username = input("What is your username? ")
password = input("What is your password? ")
return {"username": username, "password": password}
def checkLogin(adminList, user_info):
if user_info in adminList:
loggedIn = True
print("------")
print("YOU HAVE LOGGED IN!")
else:
loggedIn = False
print("------")
print("Login Failed")
return
logged = False
while not logged:
user_info = getCreds()
is_admin = checkLogin(adminList, user_info)
if is_admin:
logged = True
如果我输入了正确的密码,我会得到我已经登录的结果。但是循环不会结束
结果
What is your username? d
What is your password? d
------
Login Failed
What is your username? root
What is your password? toor
------
YOU HAVE LOGGED IN!
What is your username?
答案 0 :(得分:0)
您需要修改功能:
def checkLogin(adminList, user_info):
if user_info in adminList:
...
return True
else:
...
return False
while not logged:
...
if is_admin:
break