实现一个简单的单词本,
- 添加一个单词和词意,当添加的单词存在时让用户知道
- 可以查找单词,当查找的单词不存在时,告诉用户
- 可以删除单词,当删除的单词不存在时,可以让用户知道
- 以上功能可以无限制操作,检查到用户输入“bye”停止操作
#coding=utf-8
word_dict = {}
help = """
1:add a word
2:find a word meaning
3:delete a word
input bye to exit"""
print help
while 1:
command = raw_input("Please input your command:")
if command ==str(1):
word = raw_input("please input your word : ")
word_meaning = raw_input("please input your word meaning:")
if word_dict.has_key(word):
continue
word_dict[word] = word_meaning
if command ==str(2):
word = raw_input("Please input your word to find:")
if word_dict.has_key(word):
print word_dict[word]
continue
print "the word is not found!"
if command ==str(3):
word = raw_input("Please input your word to delet:")
if word_dict.has_key(word):
del word_dict[word]
continue
print "delete is done"
print "world to delete is not found"
if command =="bye":
break
注:以上代码是光荣之路老师吴晓华写的