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并嘗試通過字典實現相同的功能會更好
添加回答
舉報