python如何制作英文字典
作者:黑脉金 时间:2021-12-01 10:30:00
本文实例为大家分享了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 0
def 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()
来源:https://blog.csdn.net/suguoliang/article/details/88237424
标签:python,英文字典
0
投稿
猜你喜欢
流行WEB开发语言比较之ASP篇
2007-12-23 17:23:00
python设计模式之抽象工厂模式详解
2023-06-11 22:15:51
python traceback捕获并打印异常的方法
2022-11-06 10:35:30
如何利用pytesseract识别图片中的数字
2023-07-11 12:48:36
详细解析Python当中的数据类型和变量
2023-01-18 23:27:07
实例讲解MySQL数据库中文问题的解决方法
2008-12-31 15:15:00
Python heapq库案例详解
2022-12-27 12:26:52
SQLServer 全文检索(full-text)语法
2011-12-01 10:38:22
如何在SQL Server数据库中加密数据
2008-12-18 14:27:00
Oracle存储过程基本语法介绍
2023-06-27 14:00:26
python Yaml、Json、Dict之间的转化
2022-05-15 02:26:17
Python Pygame实现俄罗斯方块
2023-03-17 07:18:03
Python实现桶排序与快速排序算法结合应用示例
2022-10-26 23:33:39
Python生成pdf目录书签的实例方法
2023-10-11 15:43:21
python+opencv实现的简单人脸识别代码示例
2021-06-15 01:02:27
基于Python实现经典植物大战僵尸游戏
2021-01-28 11:17:20
JavaScript登录验证码的实现
2023-08-23 21:03:12
Python快速查找list中相同部分的方法
2021-01-28 17:26:00
利用Python爬虫给孩子起个好名字
2022-04-25 23:40:29
python使用socket进行简单网络连接的方法
2021-05-16 22:53:03