当我输入错误的用户名和密码时程序正常工作,但我输入了正确的凭证后,它仍然返回,我创建了一个使用名为“authenticateuser”的函数的脚本失败。尝试移动的东西,但无法找到解决方案。东西不对,或者我错过了一些最终的代码?带功能的登录脚本无法验证用户
loggedin = False
wrongcount = 0
def authenticateuser(theusername, thepassword):
theusername = "homerjsimpson"
thepassword = "marge"
def main():
username = ""
password = ""
while loggedin == False and wrongcount < 5:
username = input("Please enter username: ")
password = input("Please enter password: ")
if password == authenticateuser and username == authenticateuser:
loggedin = True
else:
print("Authentication Failed")
wrongcount = wrongcount + 1
loggedin = False
if(loggedin == True):
print("Welcome to the program!")
else:
print("Locked Out")
main()
'authenticateuser(..)函数做,这个语句做什么:'如果密码== authenticateuser和用户名== authenticateuser:' – thebjorn
从我的新手的理解,如果代码运行时没有函数,它会看起来像'如果密码== thepassword和用户名== theusername'。但是因为我创建了'authenticateuser'函数,我将它们替换为调用该函数。不知道是否清除它? –
你在哪里调用这个函数?函数返回什么? – thebjorn