[英]Python tkinter combobox, how can I select dictionary key and print corresponding value?
[英]how to print value to corresponding key in python
我正在嘗試打印輸入的關鍵字的相應值。 因此,如果user_input == key print(value)沒有錯誤,但是需要為所需的輸出更正代碼。 請幫忙。
user_input = input("Type in a word to retrieve it's opposite: ")
my_dict = {
'hot': 'cold',
'wet': 'dry',
'soft': 'hard',
'tall': 'short',
'flat': 'round',
'skinny': 'fat'
}
for key, value in my_dict.items():
if user_input in my_dict.keys():
print(value)
try:
print(my_dict[user_input])
except NameError:
print(“Please enter valid input”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.