鱼C论坛

 找回密码
 立即注册
查看: 1645|回复: 4

[原创] 根据小甲鱼课后作业,自己写了一个英语听写小程序 不足之处请指教

[复制链接]
发表于 2020-5-21 17:55:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
根据小甲鱼课后作业,自己写了一个英语听写小程序
代码如下 不足之处请指教


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[position]
            del list_meaning[position]
            del False_count[position]
            del total_num[position]

        else:

            msgbox(msg = "该单词不存在!",title = "单词管理器")

        end()

    if a == "修改某个单词":

        word,chr_meaning = multenterbox(title = "单词管理器",fields = ["单词","修改释义为"])
        position = list_word.index(word)
        meaning = list_meaning[position]
        b = ynbox(msg = "是否将【%s】改为【%s】"%(meaning,chr_meaning),title = "单词管理器")

        if b is True:
            list_meaning[position] = 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[position]
            count_False = False_count[position]
            num = total_num[position]

            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[position]
                del count_False
                del list_meaning[position]
                del list_word[position]

        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[n]

                    position = list_word.index(word)
                    b = total_num[position]
                    b = int(b) + 1
                    total_num[position] = 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[n]
                    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[position]
                        a = int(a) + 1
                        False_count[position] = 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[n]
                    meaning = list_meaning[n]

                    position = list_word.index(word)
                    b = total_num[position]
                    b = int(b) + 1
                    total_num[position] = 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[n]

                    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[position]
                        a = int(a) + 1
                        False_count[position] = a

                msgbox(msg = "本次测试一共测试了%s个单词,其中正确个数为%s,正确率为%s"%(A,count,str((count/A)*100) + "%"),title = "单词管理器")

                end()

main()
sub()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-5-21 17:57:44 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-5-22 09:27:51 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-5-22 09:28:54 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-5-22 10:25:18 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-2 04:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表