This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具/试卷答案生成.ipynb

127 lines
5.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"正在生成: 01_集合与逻辑答案\n",
"0\n",
"正在生成: 02_等式与不等式答案\n",
"0\n",
"正在生成: 03_幂指对函数答案\n",
"0\n",
"正在生成: 04_函数的概念与性质答案\n",
"0\n",
"正在生成: 05_函数综合答案\n",
"0\n",
"正在生成: 06_三角与解三角形答案\n",
"0\n",
"正在生成: 07_三角函数答案\n",
"0\n",
"正在生成: 08_平面向量与复数答案\n"
]
}
],
"source": [
"import os,re,json\n",
"\n",
"# filename = r\"C:\\Users\\weiye\\Documents\\wwy sync\\23届\\第二轮复习讲义\\09_立体几何综合.tex\"\n",
"filelist = ['C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\01_集合与逻辑.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\02_等式与不等式.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\03_幂指对函数.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\04_函数的概念与性质.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\05_函数综合.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\06_三角与解三角形.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\07_三角函数.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\08_平面向量与复数.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\09_立体几何综合.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\10_空间向量与应用.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\11_直线与圆.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\12_圆锥曲线.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\13_解析几何综合.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\14_等差数列和等比数列.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\15_数列综合.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\16_导数及其应用.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\17_计数原理与二项式定理.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\18_概率与统计.tex',\n",
" 'C:\\\\Users\\\\weiye\\\\Documents\\\\wwy sync\\\\23届\\\\第二轮复习讲义\\\\19_统计.tex']\n",
"pdf_dir = \"临时文件\"\n",
"\n",
"for filename in filelist:\n",
" outfilename = os.path.split(filename)[1][:-4]+\"答案\"\n",
" print(\"正在生成: \",outfilename)\n",
" with open(filename,\"r\",encoding = \"u8\") as f:\n",
" data = f.read()\n",
" with open(\"../题库0.3/Problems.json\",\"r\",encoding = \"u8\") as f:\n",
" pro_dict = json.loads(f.read())\n",
"\n",
" ids = re.findall(r\"\\((\\d{6})\\)\",data)\n",
"\n",
" output_data = \"\"\n",
" for id in ids:\n",
" problemset = pro_dict[id]\n",
" content = problemset[\"content\"]\n",
" solution = problemset[\"solution\"]\n",
" answer = \"\\\\textcolor{red}{\" + (problemset[\"ans\"] if problemset[\"ans\"] != \"\" else \"\\\\textcolor{blue}{暂无答案}\") + \"}\"\n",
" output_data += \"\\\\item \" + \"(\"+id+\") \" + content + \"\\n\\n\" + \"答案: \" + answer + \"\\n\\n\" \n",
"\n",
" with open(\"模板文件/日常选题讲义模板.txt\",\"r\",encoding = \"u8\") as f:\n",
" outlatex = f.read()\n",
"\n",
" outlatex = outlatex.replace(\"待替换1\",output_data)\n",
" outlatex = outlatex.replace(\"标题文字待处理\",outfilename.replace(\"_\",\"-\"))\n",
"\n",
" outfile = os.path.join(\"临时文件\",outfilename+\".tex\")\n",
" with open(outfile,\"w\",encoding=\"u8\") as f:\n",
" f.write(outlatex)\n",
"\n",
" outfile = outfile.replace(\"\\\\\",\"/\")\n",
"\n",
" os.system(\"xelatex -interaction=batchmode -output-directory=\" + pdf_dir + \" \"+ outfile)\n",
" print(os.system(\"xelatex -interaction=batchmode -output-directory=\" + pdf_dir + \" \"+ outfile))\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "pythontest",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "91219a98e0e9be72efb992f647fe78b593124968b75db0b865552d6787c8db93"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}