1、目标
******欢迎使用单词本*****
1、添加单词``
2、查找单词
3、删除单词
4、退出单词
******谢谢使用单词本*****
请选择:
代码为:估计还有bug待以后在次完善
#encoding=utf-8
WordLibrary = {} #存放单词库
words = '' #查找单词
Explain = '' #词义
determine = '' #判断是否删除
#1、添加单词
def add_words():
while True:
words = str(raw_input("\n请输入要添加的单词,输入“exit”退出\n".decode("utf-8").encode("gbk"))) #Please add the list to the word library, type exit from the word library
Explain = str(raw_input("\n请输入要添加的词义,输入“exit”退出\n".decode("utf-8").encode("gbk")))
if words == "exit" or Explain == "exit":
break
WordLibrary[str(words)] = str(Explain)
print u'单词添加成功,请继续使用!\n'
#2、查找单词
def find_words():
words = str(raw_input("请输入要查找的单词:\n".decode("utf-8").encode("gbk"))) #Please enter to find words
print u"你输入的单词是:",words
for key in sorted(WordLibrary.keys()):
if str(words) == key:
print u'你查找的单词是:',key,WordLibrary[key]
break
else:
print u'你查找的单词不存在\n'
#3、删除单词
def del_words():
words = str(raw_input("请输入要删除的单词:\n".decode("utf-8").encode("gbk"))) #Please enter the word to delete
for key in sorted(WordLibrary.keys()):
if str(words) == key:
print u'你查找的单词是:', key, WordLibrary[key]
determine = str(raw_input("请确定是否删除,输入 y or n :\n".decode("utf-8").encode("gbk")))
if determine == 'Y' or determine == 'y':
del WordLibrary[words]
else:
print u'你要删除的单词不存在'
break
print u'操作完毕!\n'
def out_word():
print u'谢谢使用!!'
return
def menu_print():
print u'******欢迎使用单词本*****'
print u'1、添加单词'
print u'2、查找单词'
print u'3、删除单词'``
print u'4、退出单词'
print u'******谢谢使用单词本*****'
def print_menu():
menu_print()
number = 0
while True:
print u'请选择:'
try:
number = int(raw_input("\n请选择菜单:\n".decode("utf-8").encode("gbk")))
except IOError:
print u'请在输入\n'
if number == 1 :
add_words()
continue
elif number == 2 :
find_words()
continue
elif number == 3 :
del_words()
continue
elif number == 4 :
out_word()
break
else:
print u'\n你选择的不存在程序退出服务\n'
break
print_menu()
共同学习,写下你的评论
评论加载中...
作者其他优质文章