![](/img/trans.png)
[英]How do I create corresponding values based on the metadata dictionary in pandas data frame?
[英]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
if
您在第二個中缺少字典的名稱:
if pw_entry == user_data_base[current_user]:
# Here ----^
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.