失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python中文词典构建_python-构建英语学习词典

python中文词典构建_python-构建英语学习词典

时间:2023-09-14 21:04:09

相关推荐

python中文词典构建_python-构建英语学习词典

1.从网上下载一个机器学习有关的中英文对照文件,转换为csv文件格式。

import numpy

import os

#-------------------------------------------------

filename="C:/Users/jcy/Desktop/222.csv"

if os.path.isfile(filename)==False:

print("文件不存在")

#-----------------------------------------------

import time

dictD={}

import csv

file_reader = csv.reader(open(filename, 'r'), delimiter=',')

yindex=0

for row in file_reader:

rowlen=len(row)

if(row[2].strip()=="" and row[0].strip()!=""):

yindex+=1

dictD[yindex]=(row[0],row[1])

else:

yindex+=1

dictD[yindex]=(row[1],row[2])

print("现在你的可以进入单词学习时间了:\n")

start=time.clock()

import random

import numpy as np

from numpy import *

right=0;error=0

while True:

exitword=input("是否退出(Y y or N n)\n")

if exitword=="Y" or exitword=="y":

end=time.clock()

print("您共学习了:"+str(end-start)+"秒。")

break

sJ=numpy.random.randint(1,yindex)

print("中文意思是:",dictD[sJ][1])

ff=input("请输入英文:")

if (ff.strip()==dictD[sJ][0]):

print("good!")

right=right+1

else:

print("正确答案应该为:",dictD[sJ][0])

error=error+1

print("共答对了"+str(right)+"次,"+"答错了:"+str(error)+"次。")

print("谢谢您的使用!")

如果觉得《python中文词典构建_python-构建英语学习词典》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。