【发布时间】:2022-01-15 02:08:53
【问题描述】:
我只打印存储在字典中的相应缩写有点问题
user = input("Enter a Abbreviation: ")
dictionary = {"ADSL": "Application Programming Interface",
"IDE": "Integrated Development Enviroment",
"SDK": "Software Development Kit",
"UI": "User Interface",
"UX": "User eXperience",
"OPP": "Object Oriented Programming"
}
for x in dictionary:
if user in x:
print(user + ":" + " " + dictionary[x])
elif x != dictionary:
print("Abbreviation not found")
这是我的输出
Enter a Abbreviation: UI
Abbreviation not found
Abbreviation not found
Abbreviation not found
UI: User Interface
Abbreviation not found
Abbreviation not found
我只需要输入的缩写键值而不是所有的 Abbreviation not found 输出,我希望这是有道理的
【问题讨论】:
-
什么你不只是删除
elif部分?也许您也可以尝试输入您想要的输出。
标签: python dictionary for-loop