python如何制作英文字典
Python  /  管理员 发布于 7年前   248
本文实例为大家分享了python制作英文字典的具体代码,供大家参考,具体内容如下
功能有添加单词,多次添加单词的意思,查询,退出,建立单词文件。
keys=[]dic={}def rdic(): fr = open('dic.txt','r') for line in fr: line = line.replace("\n",'') v = line.split(':') dic[v[0]] = v[1] keys.append(v[0]) fr.close()def centre(): n = input("请输入进入相应模块(添加、查询、退出):") if n == "添加": key= input("plsease input English:") if key not in keys: value=input("please input Chinese:") dic[key]=value keys.append(key) else : t=input("如果添加新的意思请输入 Y,否则输入N:") if ( t=='Y'): temp="" temp=temp+dic[key] key1= input("请输入中文") temp=temp+","+key1 print(temp) #keys.append(temp) dic[key]=temp print(dic) return 0 else: return 0 elif n== "查询": key= input("plsease input English:") print(keys) print(dic) if key not in keys: print("the english not in the dic.") else : print(dic[key]) elif n == "退出" : return 1 else : print("输入有误") return 0def wdic(): #print("!") with open('dic.txt','w') as fw: for k in keys: fw.write(k+':'+dic[k]+'\n')def main(): rdic() while True: print(keys) print(dic) n=centre() print(keys) print(dic) if n==1: break if n==0: continue wdic()main()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号