python习题库39-44

习题39、实现一个简单的单词本(不会)

  • 功能:
  • 可以添加单词和词义,当所添加的单词已存在,让用户知道;
  • 可以查找单词,当查找的单词不存在时,让用户知道;
  • 可以删除单词,当删除的单词不存在时,让用户知道;
  • 以上功能可以无限制操作,直到用户输入bye退出程序
info = """
add: add the word and word mean
find: find the word
del : delete the word
bye :quit the program
"""
print(info)
word_list_dict = {}
while True:
    command = input("please input the command:")
    if command == "add":
        word = input('input the word: ')
        word_mean = input("input the word mean: ")
        if word not in word_list_dict:
            word_list_dict[word] = word_mean
        else:
            print("alreay exists")
    elif command == "find":
        word = input('input the find word: ')
        if word in word_list_dict:
            print(word_list_dict[word])
        else:
            print("not exists")
    elif command == "del":
        word = input('input the find word: ')
        if word not in word_list_dict:
            print(

你可能感兴趣的:(python习题库)