赞
踩
实现一个简单的单词本,
#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
注:以上代码是光荣之路老师吴晓华写的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。