[小学|初中|高中][人教版|译林版]英语单词分类查询和默写程序源代码
本帖最后由 panison 于 2021-8-29 10:49 编辑链接:https://pan.baidu.com/s/1G6u8jYdCMftw4NOQx_wXTw
提取码:eokg
----------------------------------------------------------------------
原链接地址失效。重新分享了一下。编译好的EXE文件传百度网盘了。以上地址下载即可。
2021-4-3:
为了帮助家里小孩学习和记忆英语单词,因此开发了这样一个小程序。
单词的中文翻译爬取自有道翻译。已经预先写入在文件中。
程序会自动统计默写错误的单词,以方便查询和输出。
-------------------------------------------------------------------------------------
2021-4-6:
程序源代码修改(程序源代码以贴出的为准):
1、由于中文翻译中涉及人名的会显示英文,起不到默写的作用。因此,默写时,将翻译中的人名用*等长度替换;
2、修改了部分不合理的地方。
程序运行界面:
程序源代码:
""""
@说明:首发52pojie
"""
import random as r
words = dict()
a, b, c = "", "", ""
# 新建函数 get_inputs(),获取输入数据
def get_inputs():
global a, b, c
print("========================请选择功能========================")
a = input("请选择功能编号::")
if a not in ("0", "1"):
a = "0"
if a == "0":
b = input("请选择查询结果保存模式:")
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
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)、请输入学习阶段编号:")
publish = input("(4)、请输入教材版本编号:")
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 = ("小学", "初中", "高中")
else:
grade = "NULL"
if publish.strip() in ("0", "1"):
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 == grade and publish in words.split("|") and int(words) >= int(error_count):
words_get_dic = words
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.split("|") and int(words) >= int(error_count):
words_get_dic = words
if word == "NULL" and grade != "NULL" and publish == "NULL":# 101
for key in words.keys():
if len(key) >= int(ch_count) and words == grade and int(words) >= int(error_count):
words_get_dic = words
if word == "NULL" and grade == "NULL" and publish == "NULL":# 111
for key in words.keys():
if len(key) >= int(ch_count) and int(words) >= int(error_count):
words_get_dic = words
if word != "NULL":# 010,001,011,000
for key in words.keys():
if key == word:
words_get_dic = words
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 + "\t" + dic + "\t" + dic + "\t" + dic + "\t" + dic + "\n")
if mode == 1:# 背诵模式
f.write("单词:" + key + "\n")
f.write("音标:" + dic + "\n")
f.write("释义:\n")
ls = dic.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.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 :
rm = 0
ch_dic = dict()
for i in range(len(key)):
ch_dic = key
for j in r.sample(ch_dic.keys(), len(key) - rm):
ch_dic = "_"
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 = str(int(words) + 1)
print("累计默写错误次数:", words)
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")
sevenyu 发表于 2021-7-14 11:39
可否发英语单词分类查询和默写程序,谢谢!
链接:https://pan.baidu.com/s/1PDVNZoKQfIpJvkBjNdS48Q
提取码:d3ex
----------------------------------------------------------------------
我传百度网盘了。以上地址下载即可。 panison 发表于 2021-4-7 17:25
其实,我也在找外研社小中高的Excel版本的单词。找到的话可以加到里面。
单词的中文翻译爬取自有道翻译 这个能分享一份么~{:1_918:} 沙发?希望软件做的再美观直接点 gamer8263 发表于 2021-4-3 14:24
沙发?希望软件做的再美观直接点
谢谢建议!以后会开发图形用户界面。:handshake 求外研社版单词。 正在找这种,谢谢分享。 dreamrise 发表于 2021-4-7 10:30
求外研社版单词。
其实,我也在找外研社小中高的Excel版本的单词。找到的话可以加到里面。 用什么软件运行能跟你这个一样的,我查询一个单词,每次点击txt文件才能看到 满眼星辰 发表于 2021-4-9 21:46
用什么软件运行能跟你这个一样的,我查询一个单词,每次点击txt文件才能看到
你如果需要打包好了的程序,请留下邮箱。 panison 发表于 2021-4-10 17:29
你如果需要打包好了的程序,请留下邮箱。
649897220@qq.com,感谢老哥