功能:
可以添加单词和词义,当所添加的单词已存在有相应提示
可以查找单词,当查找的单词不存在时有相应提示
可以删除单词,当删除的单词不存在时有相应提示
以上功能可以无限制操作,直到用户输入bye退出程序
dict = {}
while 1:
command = input("Please input your command: ")
if command == "add":
new_word = input("Please input the word want to add: ")
if new_word in dict:
print("The word already exist.")
continue
meaning = input("Please input the corresponding meaning to the word: ")
dict[new_word] = meaning
print("Thanks! The following new word has been added: %s" % new_word)
print("Continue input your command.")
elif command == "search":
keyword = input("Please input the word want to search: ")
if keyword in dict:
print("Found it!")
else:
print("Not found.")
print("Continue input your command.")
elif command == "delete":
word_for_delete = input("Please input the word want to delete: ")
if word_for_delete not in dict:
print("Not found. Not able to delete.")
else:
dict.pop(word_for_delete)
print("%s is deleted successfully." % word_for_delete)
print("Continue input your command.")
elif command == "bye":
print("Exit the program.")
break
else:
print("Wrong command. Please input again.")
continue