小程序:用户查找英语单词的意思 ← Python字典

【程序分析】
● 字典中的
条目没有顺序的。
● 可以对字典使用如下方法:
keys()、values()、 items()、 clear()、 get(key)、 pop(key) popitem()
小程序:用户查找英语单词的意思 ← Python字典_第1张图片

【程序代码】

dictionary={
    "dog":"狗",
    "apple":"苹果",
    "banana":"香蕉",
    "cat":"猫",
    "peach":"桃子"
}

def find(word):
    return dictionary.get(word, "Sorry,no finding.")

while True:
    x=input("Please input a word (input q to exit):")
    if x=="q":
        break
    meaning=find(x)
    #print(f"{x}'s meaning:{meaning}")
    print("{}'s meaning:{}".format(x,meaning))


【程序输出】

Please input a word (input q to exit):dog
dog's meaning:狗
Please input a word (input q to exit):cat
cat's meaning:猫
Please input a word (input q to exit):op
op's meaning:Sorry,no finding.
Please input a word (input q to exit):q
>>> 







 

你可能感兴趣的:(Python程序设计,Python,字典)