我希望每个用户都拥有权限级别。
1级是客户级别。
2级是经理级别。
在注册功能中我问;用户名,密码以及用户应该达到的级别,并保存在" users.txt"中。这是一个样本:
username pass 1
usereman ssap 2
nameuser psap 1
我的登录功能:
def login():
print("\nYou're in login section")
username = input("Username: ")
password = input("Password: ")
for line in open("users.txt", "r").readlines():
login_info = line.split()
if username == login_info[0] and password == login_info[1]:
if login_info[2] == 1:
print("Dear customer, I'll take you to the marketplace.")
return True
elif login_info[2] == 2:
print("Welcome manager!")
return True
else:
print("Authority level is other than 1 or 2. Fix it!")
welcome()
但是每次我登录它都会成为其他部分。怎么了?
答案 0 :(得分:0)
我这样纠正了
if login_info[2] == "1":
print("Dear customer, I'll take you to the marketplace.")
return True
elif login_info[2] == "2":
print("Welcome manager!")
return True
它必须是字符串控件