吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6047|回复: 30
收起左侧

[Python 转载] [小学|初中|高中][人教版|译林版]英语单词分类查询和默写程序源代码

   关闭 [复制链接]
panison 发表于 2021-4-3 14:01
本帖最后由 panison 于 2021-8-29 10:49 编辑

链接:https://pan.baidu.com/s/1G6u8jYdCMftw4NOQx_wXTw
提取码:eokg
----------------------------------------------------------------------
原链接地址失效。重新分享了一下。编译好的EXE文件传百度网盘了。以上地址下载即可。


2021-4-3:
为了帮助家里小孩学习和记忆英语单词,因此开发了这样一个小程序。
单词的中文翻译爬取自有道翻译。已经预先写入在文件中。


程序会自动统计默写错误的单词,以方便查询和输出。

-------------------------------------------------------------------------------------

2021-4-6:

程序源代码修改(程序源代码以贴出的为准):

1、由于中文翻译中涉及人名的会显示英文,起不到默写的作用。因此,默写时,将翻译中的人名用*等长度替换;

2、修改了部分不合理的地方。



程序运行界面:


0.png

1.png

3.png

程序源代码:
[Python] 纯文本查看 复制代码
""""
@说明:首发52pojie
"""
import random as r

words = dict()
a, b, c = "", "", ""


# 新建函数 get_inputs(),获取输入数据
def get_inputs():
    global a, b, c
    print("========================请选择功能========================")
    a = input("请选择功能编号:[0.查询,1.默写]:")
    if a not in ("0", "1"):
        a = "0"
    if a == "0":
        b = input("请选择查询结果保存模式:[0.数据模式,1.背诵模式]")
        if b not in ("0", "1"):
            b = "0"
        else:
            pass
    else:
        b = input("请输入默写单词的个数:")
        if not b.isnumeric():
            b = "0"
        c = input("请输入默写时,单词中已知字符的个数:")
        if not c.isnumeric():
            c = "0"


# 新建函数 txt_to_dic(),将txt文件转换为字典
def txt_to_dic(filename):
    dic = dict()
    with open(filename, "rt", encoding="utf-8-sig") as f:
        lines = f.readlines()
        for line in lines:
            ls = line.strip("\n").split("\t")
            dic[ls[0]] = ls[1:]
    return dic


# 新建函数 words_get(),批量获取单词
def words_get(filename):
    global words
    words = txt_to_dic(filename)
    words_get_dic = dict()

    print("============批量获取单词(用于:输出查询结果/从中抽样默写)============")

    # 输入查询条件
    print("提示:按Enter可以略过条件。")
    word = input("(1)、请输入单个单词文本:")
    ch_count = input("(2)、请输入单个单词最低长度:")
    grade = input("(3)、请输入学习阶段编号[0.小学,1.初中,2.高中]:")
    publish = input("(4)、请输入教材版本编号[0.人教版,1.译林版]:")
    error_count = input("(5)、请输入单词最低出错次数:")

    # 对查询条件进行加工赋值
    if word.strip() == "":
        word = "NULL"
    if not ch_count.strip().isnumeric():
        ch_count = "0"
    if grade.strip() in ("0", "1", "2"):
        grade = ("小学", "初中", "高中")[int(grade)]
    else:
        grade = "NULL"
    if publish.strip() in ("0", "1"):
        publish = ("人教版", "译林版")[int(publish)]
    else:
        publish = "NULL"
    if not error_count.strip().isnumeric():
        error_count = "0"

    # 多条件组合
    if word == "NULL" and grade != "NULL" and publish != "NULL":  # 100
        for key in words.keys():
            if len(key) >= int(ch_count) and words[key][0] == grade and publish in words[key][1].split("|") and int(words[key][4]) >= int(error_count):
                words_get_dic[key] = words[key]
    if word == "NULL" and grade == "NULL" and publish != "NULL":  # 110
        for key in words.keys():
            if len(key) >= int(ch_count) and publish in words[key][1].split("|") and int(words[key][4]) >= int(error_count):
                words_get_dic[key] = words[key]
    if word == "NULL" and grade != "NULL" and publish == "NULL":  # 101
        for key in words.keys():
            if len(key) >= int(ch_count) and words[key][0] == grade and int(words[key][4]) >= int(error_count):
                words_get_dic[key] = words[key]
    if word == "NULL" and grade == "NULL" and publish == "NULL":  # 111
        for key in words.keys():
            if len(key) >= int(ch_count) and int(words[key][4]) >= int(error_count):
                words_get_dic[key] = words[key]
    if word != "NULL":  # 010,001,011,000
        for key in words.keys():
            if key == word:
                words_get_dic[key] = words[key]

    return words_get_dic


# 新建函数dic_to_txt(),将字典转为txt文件
def dic_to_txt(filename, dic, mode):
    with open(filename, "w+", encoding="utf-8") as f:
        for key in dic.keys():
            if mode == 0:  # 数据模式
                f.write(key + "\t" + dic[key][0] + "\t" + dic[key][1] + "\t" + dic[key][2] + "\t" + dic[key][3] + "\t" + dic[key][4] + "\n")
            if mode == 1:  # 背诵模式
                f.write("单词:" + key + "\n")
                f.write("音标:" + dic[key][2] + "\n")
                f.write("释义:\n")
                ls = dic[key][3].split("|")
                for i in ls:
                    f.write("   " + i + "\n")
                f.write("\n")


# 新建函数write_from_mem(),根据中文意思默写单词
def write_from_mem(dic, n, rm=0):
    print("========================批量默写单词========================")
    if len(dic) == 0 or n == 0:
        print("无可默写的单词!")
    else:
        if n >= len(dic):
            n = len(dic)
        sample_keys = r.sample(dic.keys(), n)
        n = 0
        e = 0
        for key in sample_keys:
            print("默写序号:", n+1)
            print("单词释义:")
            for i in dic[key][3].split("|"):
                if key in i:
                    i = i.replace(key, "*"*len(key))
                if key.lower() in i:
                    i = i.replace(key.lower(), "*" * len(key))
                if key.upper() in i:
                    i = i.replace(key.upper(), "*" * len(key))
                if key.capitalize() in i:
                    i = i.replace(key.capitalize(), "*" * len(key))
                print("    " + i)
            # 限制默写提示的字符个数
            if rm not in [i for i in range(len(key) + 1)]:
                rm = 0
            ch_dic = dict()
            for i in range(len(key)):
                ch_dic[i] = key[i]
            for j in r.sample(ch_dic.keys(), len(key) - rm):
                ch_dic[j] = "_"
            rm_txt = "".join(ch_dic.values())
            print("单词提示:", rm_txt)
            word_write = input("请输入默写的单词(不区分大小写):").strip()
            if word_write.lower() == key.lower():
                print("默写结果:正确!。")
            else:
                print("默写错误:错误!正确答案为:" + key, end=",")
                e = e + 1
                words[key][4] = str(int(words[key][4]) + 1)
                print("累计默写错误次数:", words[key][4])
            print("\n")
            n = n + 1
        print("默写完毕!共默写{0:}个单词,错误{1:}个单词,正确率{2:.2%}!".format(n, e, ((n-e)/n)))


# 定义主函数main(data_filename, output_filename)
def main(data_filename, output_filename):
    get_inputs()
    if a == "0":  # 查询功能
        dic_to_txt(output_filename, words_get(data_filename), int(b))
        print("查询完毕!查询结果保存在当前目录下{}中。".format(output_filename))
    if a == "1":  # 默写功能
        write_from_mem(words_get(data_filename), int(b), int(c))
        dic_to_txt(data_filename, words, 0)  # 更新单词默写错误的次数


if __name__ == '__main__':
    main("英语词汇.txt", "查询结果.txt")


3.单词查询和默写.zip (284.91 KB, 下载次数: 236)



免费评分

参与人数 4吾爱币 +7 热心值 +4 收起 理由
sevenyu + 1 + 1 谢谢@Thanks!
Cool_Breeze + 1 + 1 谢谢@Thanks!
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
Tank2021 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| panison 发表于 2021-7-14 16:07
sevenyu 发表于 2021-7-14 11:39
可否发英语单词分类查询和默写程序,谢谢!

链接:https://pan.baidu.com/s/1PDVNZoKQfIpJvkBjNdS48Q
提取码:d3ex
----------------------------------------------------------------------
我传百度网盘了。以上地址下载即可。
dreamrise 发表于 2021-4-7 22:03
panison 发表于 2021-4-7 17:25
其实,我也在找外研社小中高的Excel版本的单词。找到的话可以加到里面。

单词的中文翻译爬取自有道翻译 这个能分享一份么~
gamer8263 发表于 2021-4-3 14:24
 楼主| panison 发表于 2021-4-3 17:53
gamer8263 发表于 2021-4-3 14:24
沙发?希望软件做的再美观直接点

谢谢建议!以后会开发图形用户界面。
dreamrise 发表于 2021-4-7 10:30
求外研社版单词。
cgh 发表于 2021-4-7 12:52
正在找这种,谢谢分享。
 楼主| panison 发表于 2021-4-7 17:25
dreamrise 发表于 2021-4-7 10:30
求外研社版单词。

其实,我也在找外研社小中高的Excel版本的单词。找到的话可以加到里面。
满眼星辰 发表于 2021-4-9 21:46
用什么软件运行能跟你这个一样的,我查询一个单词,每次点击txt文件才能看到
 楼主| panison 发表于 2021-4-10 17:29
满眼星辰 发表于 2021-4-9 21:46
用什么软件运行能跟你这个一样的,我查询一个单词,每次点击txt文件才能看到

你如果需要打包好了的程序,请留下邮箱。
满眼星辰 发表于 2021-4-11 06:44
panison 发表于 2021-4-10 17:29
你如果需要打包好了的程序,请留下邮箱。

649897220@qq.com,感谢老哥
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-13 06:43

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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