[英]How do I use a if statement to access values in a dictionary based on the corresponding key?
I thought I could use a dictionary to store key/value pairs for user's names and passwords.我想我可以使用字典来存储用户名和密码的键/值对。 How do I use a if statement to access values in a dictionary based on the corresponding key?
如何使用 if 语句根据相应的键访问字典中的值?
users_data_base = dict(Mike = "Speedy203", Ken = "Justify30", Marvin = "Pop_Jay")
while True:
current_user = input("Enter User Name: ")
if current_user not in users_data_base:
print("User name not valid")
else:
print("Welcome " + current_user)
break
while True:
pw_entry = input("Please enter password: ")
if pw_entry is ([current_user]):
print("Incorrect password entry")
print("Try again")
else:
print("Successful entry")
break
You are missing the dictionary's name in the second if
: if
您在第二个中缺少字典的名称:
if pw_entry == user_data_base[current_user]:
# Here ----^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.