根据小甲鱼课后作业,自己写了一个英语听写小程序 不足之处请指教
根据小甲鱼课后作业,自己写了一个英语听写小程序代码如下 不足之处请指教
from easygui import *
import random
import urllib.request
import os
w = open("list_word.txt","r")
m = open("list_meaning.txt","r")
c = open("False_count.txt","r")
t = open("total_num.txt","r")
list_word = w.read()
list_meaning = m.read()
False_count = c.read()
total_num = t.read()
list_word = eval(list_word)
list_meaning = eval(list_meaning)
False_count = eval(False_count)
total_num = eval(total_num)
w.close()
m.close()
c.close()
t.close()
def sub():
with open("list_word.txt", "w") as w:
w.write(str(list_word))
with open("list_meaning.txt", "w") as m:
m.write(str(list_meaning))
with open("False_count.txt", "w") as f:
f.write(str(False_count))
with open("total_num.txt","w") as t:
t.write(str(total_num))
def end():
a = ynbox(msg="是否继续运行?(Y/N)", title="单词管理器")
if a is True:
main()
else:
sub()
def main():
a = buttonbox(msg = "请选择指令!",title = "单词管理器",choices = ["写入新单词","删除某个单词","修改某个单词","搜索单词","更多指令"])
if a == "写入新单词":
word,meaning = multenterbox(msg = "单词与释义",title = "单词管理器",fields = ["单词","释义"])
if word not in list_word:
list_word.append(word)
list_meaning.append(meaning)
False_count.append(0)
total_num.append(0)
elif word in list_word:
msgbox(msg = "单词已存在!!!",title = "单词管理器")
end()
if a == "删除某个单词":
dis_word = enterbox(msg = "请输入要删除的单词",title = "单词管理器")
if dis_word in list_word:
position = list_word.index(dis_word)
del list_word
del list_meaning
del False_count
del total_num
else:
msgbox(msg = "该单词不存在!",title = "单词管理器")
end()
if a == "修改某个单词":
word,chr_meaning = multenterbox(title = "单词管理器",fields = ["单词","修改释义为"])
position = list_word.index(word)
meaning = list_meaning
b = ynbox(msg = "是否将【%s】改为【%s】"%(meaning,chr_meaning),title = "单词管理器")
if b is True:
list_meaning = chr_meaning
if b is False:
pass
end()
if a == "搜索单词":
search_word = enterbox(msg = "请输入需要搜索的单词",title = "单词管理器")
if search_word in list_word:
position = list_word.index(search_word)
meaning = list_meaning
count_False = False_count
num = total_num
if (count_False/num) < 0.05 and num > 40:
advise = "已熟练掌握该单词,建议删除该单词!"
else:
advise = "请继续多练习该单词!"
urllib.request.urlretrieve("http://dict.youdao.com/dictvoice?type=0&audio=" + search_word,"record.mp3")
os.system("record.mp3")
response = ynbox(msg = "单词%s的释义为【%s】,该单词出错次数为%s,总检测次数为%s,正确率为%s,%s"%(search_word,meaning,count_False,num,str((1-(count_False)/num)*100) + "%",advise),title = "单词管理器",choices = ["删除该词","不做处理"])
if response is True:
del total_num
del count_False
del list_meaning
del list_word
if search_word not in list_word:
msgbox(msg = "找不到单词!",title = "单词管理器")
end()
if a == "更多指令":
b = buttonbox(msg = "请选择指令!",title = "单词管理器",choices = ["统计总单词个数","测试单词掌握情况"])
if b == "统计总单词个数":
number = len(list_word)
msgbox(msg = "单词个数为%s"%number,title = "单词管理器")
end()
if b == "测试单词掌握情况":
response = buttonbox(msg = "请选择测试方式!",title = "单词管理器",choices = ("给英写中","给中写英"))
if response == "给英写中":
A = int(enterbox(msg = "请输入测试次数", title = "单词管理器"))
count = 0
number = len(list_word)
for i in range(A):
n = random.randint(0,number - 1)
word = list_word
position = list_word.index(word)
b = total_num
b = int(b) + 1
total_num = b
urllib.request.urlretrieve("http://dict.youdao.com/dictvoice?type=0&audio=" + word,"record.mp3")
os.system("record.mp3")
answer = enterbox(msg = "单词【%s】的意思是?(当前进度%s/%s)"%(word,i+1,A),title = "单词管理器")
meaning = list_meaning
c = ynbox(msg = "你的答案是【%s】,正确答案是【%s】\n你认为你是否是正确的(Y/N)"%(answer,meaning),title = "单词管理器")
if c is True:
count += 1
if c is False:
position = list_meaning.index(meaning)
a = False_count
a = int(a) + 1
False_count = a
msgbox(msg = "本次测试一共测试了%s个单词,其中正确个数为%s,正确率为%s"%(A,count,str((count/A)*100) + "%"),title = "单词管理器")
end()
if response == "给中写英":
A = int(enterbox(msg = "请输入测试次数", title = "单词管理器"))
count = 0
number = len(list_word)
for i in range(A):
n = random.randint(0,number - 1)
word = list_word
meaning = list_meaning
position = list_word.index(word)
b = total_num
b = int(b) + 1
total_num = b
urllib.request.urlretrieve("http://dict.youdao.com/dictvoice?type=0&audio=" + word,"record.mp3")
os.system("record.mp3")
answer = enterbox(msg = "释义为【%s】对应的单词是?(当前进度%s/%s)"%(meaning,i+1,A),title = "单词管理器")
word = list_word
if answer == word:
msgbox(msg = "答对啦!你的答案是【%s】,正确答案是【%s】!"%(answer,word))
count += 1
if answer != word:
msgbox(msg="答错啦!你的答案是【%s】,正确答案是【%s】!" % (answer, word))
position = list_meaning.index(meaning)
a = False_count
a = int(a) + 1
False_count = a
msgbox(msg = "本次测试一共测试了%s个单词,其中正确个数为%s,正确率为%s"%(A,count,str((count/A)*100) + "%"),title = "单词管理器")
end()
main()
sub() {:10_254:} {:10_256:} {:10_245:} {:10_254:}
页:
[1]