【发布时间】:2020-08-14 22:10:10
【问题描述】:
用户 = {} 状态 = ""
定义菜单(): 全球地位 status = input("你是注册用户Y/N吗?输入q退出。\n")
if status == "Y" or "y": #I wanted to make the option do capital and lowercase Y and N but when I
OldUser()
elif status == "N" or "n": #enter "n" it goes to OldUser() instead of Register()
Register()
定义寄存器(): name = input("请输入用户名:")
if name in users:
print("The username is already used. Try again.")
else:
pass_w = input("Enter a password: ")
users[name] = pass_w
print("\n Registration Complete! \n")
定义老用户(): login_n = input("请输入您的用户名:")
if login_n in users:
login_p = input("Enter your password: ")
if login_p == users[login_n]:
print("\n Login Successful! \n")
else:
print("Password incorrect!")
else:
print("\n Wrong user or user doesn't exist. \n")
而状态!=“q”: 菜单()
【问题讨论】:
-
另外,您可以将 .lower() 或 .upper() 添加到变量的末尾,以便 userInput = input('Enter y or n').lower() 然后您的 if 语句使用小写 y,即使他们使用大写字母,它也会将其转换为小写
标签: python if-statement authentication logic logical-operators