【发布时间】:2018-05-10 00:29:14
【问题描述】:
大家好,我的计算项目需要帮助,但在谷歌上找不到答案。我正在尝试制作一个基本的登录系统并有 2 个列表,一个带有用户名的列表,一个带有密码的列表:
usernames[username1, username2, username3, etc]
passwords[password1, password2, password3, etc]
我想询问用户输入用户名和密码并检查它们是否在相应的列表中。但是,如果没有人能够使用他们的用户名和其他人的密码登录,我无法弄清楚如何做到这一点。
我当前的代码是:
def Login():
usernames = [username1, username2, username3]
passwords = [password1, password2, password3]
user = input("Please enter your username: ")
pw = input("Please enter password: ")
x = 0
for x in range(len(usernames)):
if user == usernames[x] and pw == passwords[x]:
print("Login Successful")
elif user == usernames[x] and pw != passwords[x]:
print("Password does not match")
Login()
else:
print("User not recognised")
Login()
x = x + 1
我希望能够检查他们给我的用户名在列表中的哪个位置,然后在密码列表中查找该位置,如果该密码是他们提供的密码,他们就可以登录。 谢谢!
【问题讨论】:
标签: python-3.x list