制作英文学习词典。编写程序制作英文学习词典,词典有 3 个基本功能:添加、
查询和退出。程序读取源文件路径下的 txt 格式词典文件,若没有就创建一个。
词典文件存储方式为“英文单词 中文单词”,每行仅有一对中英释义。程序会根据
用户的选择进入相应的功能模块,并显示相应的操作提示。当添加的单词已存在
时,显示“该单词已添加到字典库”;当查询的单词不存在时,显示“字典库中未找
到这个单词”。用户输入其他选项时,提示“输入有误”。

Python有关制作英文学习词典问题。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 神仙别闹 2021-12-31 22:21关注
可以参考下这个
#英文字典 def oppendict(): dir = 'mydict.txt' dicts = {} tf=open(dir,'r+') print('本字典已有的内容:') for item in tf: k,v=tuple(item.replace('\n','').split(':')) print(k,v) dicts[k]=v tf.close() return dicts dicts=oppendict() #查字典 def lookup(): quest=input("请输入要查询的单词") result=dicts.get(quest,"字典库中未找到这个单词") print('该单词的解释为:'+result+'\n') #插入新单词 def inserts(): word = input("请输入要插入的单词:") if dicts.get(word): print('该单词已添加到字典库'+'\n') else: explain=input("请输入该单词的解释:") dicts[word]=explain #更新单词解释 def renew(): word = input('请输入需要更新解释的单词:') explain=input("请输入单词的新解释:") dicts[word]=explain #删除 def deldict(): word = input('请输入删除的单词:') if dicts.get(word): del dicts[word] else: print('没有这个单词') print(dicts) #存档 def savedict(): dir='mydict.txt' tf = open(dir,'w+') for item in dicts.items(): tf.write(':'.join(item) + '\n' ) tf.close() def meun(): meuns=['1.查询','2.新增','3.更新','4.删除','5.退出'] funcname = ['','lookup','inserts' ,'renew' , 'deldict'] while True: print('\n'.join(meuns)) trs = eval(input('请用数字选择:')) if trs==5: break elif trs in range(1,5): eval(funcname[trs])() else: print('输入有误'+'\n') if __name__=='__main__': print('欢迎使用本字典'.center(20,'=')) meun() print('再见'.center(20,'=')) savedict() dicts = oppendict()
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 QT 实现 RSTP 语音对讲功能
- ¥50 AES魔改之后的安全性关于PRF(相关搜索:密码学)
- ¥15 有没有谁能高分通过 reCaptcha v3验证,国外网站。有兴趣留言,有偿。
- ¥15 用C语言写的一个程序遇到了两个问题第一是偏移正确但读取不到坐标,第二个问题是自己定义的函数实现不了获取指定进程模块。
- ¥15 在安装Anaconda时总是闪退怎么办?
- ¥15 对图中电路进行以下几个方面的分析
- ¥15 对图中电路进行以下几个方面的分析
- ¥15 对图中电路进行以下几个方面的分析
- ¥15 对图中电路进行以下几个方面的分析
- ¥500 抖音主页视频预存加载卡bug