2 回答
TA贡献1801条经验 获得超16个赞
这就是您可以存储profileName和password组合dictionary并检查用户输入的方式。
profile_password_mapping = ['jc1':'123', 'jc2':'213', 'jc3':'312', 'jc4':'321', 'jc5':'231']
profileName = input('Please enter your username: ')
profilePassword = input('Please enter your password: ')
if profileName in profile_password_mapping.keys() and profile_password_mapping[profileName] == profilePassword:
print('Welcome User: {0}'.format(profileName))
else:
print("User does not exist or the password is wrong.")
TA贡献1806条经验 获得超5个赞
我想您可以使用两个列表的索引值来进行配置文件与密码匹配
Profile = ['jc1', 'jc2', 'jc3', 'jc4', 'jc5']
Passwords = ['123','213','312','321','231']
JK = raw_input('Please enter your username: ')
if JK in Profiles:
DK = raw_input('Please enter your password: ')
if DK in Passwords and Profiles.index(JK) == Password.index(DK):
print "Welcome user %s"%(JK)
else:
print "Incorrect Password"
else:
print "User %s not in Profile list"%(JK)
现在您可以使用列表,但是如果您了解dictionaries并尝试通过字典实现相同的功能会更好
添加回答
举报