我是Python新手,我想问一下如何让我的代码工作。 在login()函数中,如果用户名和密码正确,log=True,则转到main()函数时,不定义log变量
然后我在main()函数中在线找到addlog=login(),如下所示
def main():
log = login()
if log == True:
identifier = loginChoice()
if identifier == 1:
customerMain()
if identifier == 2:
adminMain()
它适用于那个些人,但对我来说,它进入了无休止的循环,不断地调用login()函数
下面是我的全部代码
def loginChoice():
print("\n","Login as:")
print("1. Customer")
print("2. Admin")
choice =int(input())
if choice == 1:
login()
return choice
if choice == 2:
login()
return choice
def login():
print("\n", "Login menu")
user = input("Username: ")
passw = input("Password: ")
fhand = open("userpassword.txt", "r")
for line in fhand.readlines():
us, pw = line.strip().split("\t")
if (user == us) and (passw == pw):
log = True
print("Login successful!")
return True
else:
print ("Wrong username/password")
return False
def main():
if log == True:
identifier = loginChoice()
if identifier == 1:
customerMain()
if identifier == 2:
adminMain()
谢谢你帮助我
登录菜单的屏幕截图在循环中
我修改了您的代码。这将正常工作
但是customerMian()和adminMain()函数没有定义
相关问题 更多 >
编程相关推荐