当前位置:   article > 正文

21:简单的单词本_please input your command

please input your command

实现一个简单的单词本,

  1. 添加一个单词和词意,当添加的单词存在时让用户知道
  2. 可以查找单词,当查找的单词不存在时,告诉用户
  3. 可以删除单词,当删除的单词不存在时,可以让用户知道
  4. 以上功能可以无限制操作,检查到用户输入“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
        
          注:以上代码是光荣之路老师吴晓华写的

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/679232
推荐阅读
相关标签
  

闽ICP备14008679号