【教学类-42-02】20231224 X-Y 之间加法题判断题2.0(按2:8比例抽取正确题和错误题)

 作品展示:

0-5: 21题,正确21题,错误21题=42题 。小于44格子,都写上,哪怕输入2:8,实际也是5:5

0-10 66题,正确66题,错误66题=132题 大于44格子,正确66题抽取44*20%=8.8=8题,错误题66题*80%=44-8=36题

背景需求:

很多大班孩子很熟练做“0-5,0-10的加法、或减法题目,需要新的题型来换花样。除了”比大小“,我能想起的就是”判断加法题答案是否正确。

1.0模板是所有的题目都是错误答案,2.0模板能控制一定比例的正确题目出现

WORD模板

代码展示:

'''
X-Y 之间的所有加法题的判断题2.0(随机生成错误答案,考虑正确和不正确题的比例,如正确数量20%,错误数量80%),
时间:2023年12月25日 21:46
作者:阿夏
'''import random
from win32com.client import constants,gencache
from win32com.client.gencache import EnsureDispatch
from win32com.client import constants # 导入枚举常数模块
import os,timeimport docx
from docx import Document
from docx.shared import Pt 
from docx.shared import RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qnfrom docxtpl import DocxTemplate
import pandas as pd
from docx2pdf import convert
from docx.shared import RGBColor# 第一步:制作不重复所有“+”、不重复所有减法# 不重复的数字题
num=int(input('打印几份(必须双数,根据人数,如32人)\n'))classroom=input('班级(输入中、大)\n')
bl=int(input('正确题的比例,如2,就是20%的正确题,80%的错误题\n'))
size=20
height1=11
weight1=4
gz=height1*weight1   # 115
sum1=int(input('X-Y以内的“+” 最小数字X(0)\n'))
sum2=int(input('X-Y以内的“+” 最大数字Y(0-99)\n'))# 5以内“+”题共21题
P1=[]# 正确for a in range(0,sum2+1):     # 起始数字就是10,就是排除掉0-10之间的数字for b in range(0,sum2+1):      # 起始数字为0,if 0<=a+b<sum2+1:     w=random.randint(sum1,sum2)        # 随机生成错误数字    # print('{}+{}='.format(a,b))            P1.append('{}+{}={}'.format('%02d'%a,'%02d'%b,'%02d'%(a+b)))if 0<=b+a<sum2+1:    # print('{}+{}='.format(a,b))P1.append('{}+{}={}'.format('%02d'%b,'%02d'%a,'%02d'%(a+b)))else:passP1 =list(set(P1))    # 排除重复,但随机打乱
P1.sort()    # 小到大排序
print(P1)
# 正确的答案
# ['00+00=00', '00+01=01', '00+02=02', '00+03=03', '00+04=04', '00+05=05', '01+00=01', '01+01=02', '01+02=03', '01+03=04', '01+04=05', '02+00=02', '02+01=03', '02+02=04', '02+03=05', '03+00=03', '03+01=04', '03+02=05', '04+00=04', '04+01=05', '05+00=05']# 新建一个”装N份word和PDF“的临时文件夹
imagePath1=r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\零时Word'
if not os.path.exists(imagePath1):  # 判断存放图片的文件夹是否存在os.makedirs(imagePath1)  # 若图片文件夹不存在就创建D=[]
for z in range(0,num):   #多少份  # 标题说明# 新建worddoc = Document(r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\04判断模板一页两份.docx')  for j in range(2):P2=[]# 不正确的答案随机抽取for p in P1:w=random.randint(sum1,sum2)        # 随机生成错误数字P2.append(p[0:6]+'{}'.format('%02d'%(w)))print(P2)# ['00+00=10', '00+01=10', '00+02=10', '00+03=10', '00+04=10', '00+05=10', '01+00=10', '01+01=10', '01+02=10', '01+03=10', '01+04=10', '02+00=10', '02+01=10', '02+02=10', '02+03=10', '03+00=10', '03+01=10', '03+02=10', '04+00=10', '04+01=10', '05+00=10']P3=P1+P2# [[],[]]print('P3长度{}'.format(len(P3)))# 二位数去0P4=[]for i  in P3:    # 每个内容是00+00=00,一共6个字符# print(i)if i[0]=='0'and i[3]=='0' and i[6]=='0':P4.append(i[1:3]+i[4:6]+i[7]) if i[0]=='0'and i[3]=='0'and i[6]!='0':P4.append(i[1:3]+i[4:]) if i[0]=='0'and i[3]!='0'and i[6]!='0':  P4.append(i[1:])if i[0]=='0'and i[3]!='0'and i[6]=='0':  P4.append(i[1:6]+i[7])if i[0]!='0'and i[3]=='0'and i[6]=='0': P4.append(i[0:3]+i[4:6]+i[7])if i[0]!='0'and i[3]!='0'and i[6]=='0':P4.append(i[0:6]+i[7])    if i[0]!='0'and i[3]=='0'and i[6]!='0':  P4.append(i[0:3]+i[4:])if i[0]!='0'and i[3]!='0'and i[6]!='0':P4.append(i)print(P4)print('{}-{}之间的加法判断题共有  {}  题'.format(sum1,sum2,len(P4)) )   # 42#  如果正确题+错误题大于44题P=[] if len(P4)>gz:        # 正确题在前,错误题在后P5=[]f=int(len(P4)/2)        # 21for e in range(int(len(P4)/f)):P5.append(P4[e*f:e*f+f])print(P5)# 随机抽取比例 共44题zq=int(gz*(bl*10/100))cw=gz-zq# 从P5[0]随机抽取20%, 从P5[1]随机抽取80%,组成P  a1=P5[0]a2=P5[1]t1=random.sample (a1,zq)t2=random.sample (a2,cw)for t3 in t1:P.append(t3)for t4 in t2:P.append(t4)# 暂时不打乱if len(P4)<=gz:for t5 in P4:P.append(t5)           # print(P)# print('{}-{}之间的加法判断题共有  {}  题'.format(sum1,sum2,len(P)) )   # 42# 第一行的班级和项目A=[]c='{}'.format(classroom)if len(P) <=gz:title='{}-{}“+”判断{}抽{}题{}:{}'.format(sum1,sum2,len(P1),len(P),bl,10-bl)if len(P) >gz:title='{}-{}“+”判断{}抽{}题{}:{}'.format(sum1,sum2,len(P1),gz,bl,10-bl)d=['0003','0006']# 表格0 表格2的 03 05单元格里写入标题信息cA.append(c)A.append(title)print(A)# 制作"单元格"bg=[]for x in range(0,weight1*3,3):       # 5   #数列 先宽 后高  for y in range(1,height1+1):      #    23s1='{}{}'.format('%02d'%y,'%02d'%x)       #数列 先y 后x  bg.append(s1)   print(bg)        print(len(bg))bg.insert(0,d[1])bg.insert(0,d[0])print(bg)print(len(bg))# 如果题目总数小于155,就提取# 例如:0-5 21题,P的第一部分是21题全部,第2部分就21题里面的随机抽屉,第3部分13也是随机抽取,可能会重复PP=[]PPP=[]PP.clear()        # P.clear()if len(P)<=gz:for l in P :         # 先写入固定的21题PP.append(l)print(PP)print('第1组长度{}'.format(len(PP)))# 0-0只有1题,所以批量155次for e in range(gz):PP.append('')                # 预留一个空行做分割线v=random.sample(P,len(P))    # 从21题随机抽取不重复21for u in v:        # 遍历提取PP.append(u)        # 添加到PPPP=PP[:gz]              # 提取前55个print('把21题批量55次后,总数量  实际提取{}格{}'.format(len(PP),len(PPP)))print(PPP)else:w=random.sample(P,len(P))    # 从21题随机抽取不重复21PPP=wPPP.insert(0,title)PPP.insert(0,classroom)print(PPP)print(len(PPP))#       # 房间模板(第一个表格)要写入的门牌号列表 table = doc.tables[j]          # 表0,表2 写标题用的# 标题写入3、5单元格  for t in range(0,len(bg)):             # 0-5是最下面一行,用来写卡片数字pp=int(bg[t][0:2])     # qq=int(bg[t][2:4])k=str(PPP[t])              # 提取list图案列表里面每个图形  t=索引数字print(pp,qq,k)# 图案符号的字体、大小参数run=table.cell(pp,qq).paragraphs[0].add_run(k)    # 在单元格0,0(第1行第1列)输入第0个图图案run.font.name = '黑体'#输入时默认华文彩云字体# run.font.size = Pt(46)  #输入字体大小默认30号 换行(一页一份大卡片run.font.size = Pt(size) #是否加粗# run.font.color.rgb = RGBColor(150,150,150) #数字小,颜色深0-255run.font.color.rgb = RGBColor(150,150,150) #数字小,颜色深0-255run.bold=True# paragraph.paragraph_format.line_spacing = Pt(180) #数字段间距r = run._elementr.rPr.rFonts.set(qn('w:eastAsia'), '黑体')#将输入语句中的中文部分字体变为华文行楷table.cell(pp,qq).paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.LEFT #居中  #       
#    doc.save(r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\零时Word\{}.docx'.format('%02d'%(z+1)))#保存为XX学号的电话号码word     time.sleep(1)from docx2pdf import convert# docx 文件另存为PDF文件inputFile = r"C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word/{}.docx".format('%02d'%(z+1))# 要转换的文件:已存在outputFile = r"C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word/{}.pdf".format('%02d'%(z+1))  # 要生成的文件:不存在# 先创建 不存在的 文件f1 = open(outputFile, 'w')f1.close()# 再转换往PDF中写入内容convert(inputFile, outputFile)print('----------第4步:把都有PDF合并为一个打印用PDF------------')# 多个PDF合并(CSDN博主「红色小小螃蟹」,https://blog.csdn.net/yangcunbiao/article/details/125248205)
import os
from PyPDF2 import PdfMerger
target_path =  'C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word'
pdf_lst = [f for f in os.listdir(target_path) if f.endswith('.pdf')]
pdf_lst = [os.path.join(target_path, filename) for filename in pdf_lst]
pdf_lst.sort()
file_merger = PdfMerger()
for pdf in pdf_lst:print(pdf)file_merger.append(pdf)if len(P) <=gz:file_merger.write("C:/Users/jg2yXRZ/OneDrive/桌面/加减法/(打印合集)05(一页两份 ){}题{}-{}加法判断题“+”共{}题抽{}题{}比{}({}共{}人打印{}张).pdf" .format(gz,'%02d'%sum1,'%02d'%sum2,'%03d'%len(P1),'%02d'%len(P), bl,int(10-bl),c,num,num))
else:file_merger.write("C:/Users/jg2yXRZ/OneDrive/桌面/加减法/(打印合集)05(一页两份 ){}题{}-{}加法判断题“+”共{}题抽{}题{}比{}({}共{}人打印{}张).pdf".format(gz,'%02d'%sum1,'%02d'%sum2,'%03d'%len(P1),gz, bl,int(10-bl),c,num,num))
#
file_merger.close()
# doc.Close()# # print('----------第5步:删除临时文件夹------------')    
import shutil
shutil.rmtree('C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word') #递归删除文件夹,即:删除非空文件夹

终端展示

2.0版判断题说明:

以0-5为例,21题,按比例抽取正确题20%和错误题80%。因为21正确题+21错误题总数42题,小于44格子,所以默认都写入表格,先正确题,后错误题,不考虑20%和80%的比例。

以0-10为例,66题,按比例抽取正确题20%和错误题80%。因为66正确题+66错误题总数132题,大于44格子,所以考虑按正确题20%和错误题80%的比例随机打乱抽取

以上为了演示正确错误题目的数量正确性,,而“先正确题”“后错误题。”

打乱时,只要把这两个取消隐藏,显示出来,就能够做出正确与错误题混合的效果

'''
X-Y 之间的所有加法题的判断题2.0(打乱版 随机生成错误答案,考虑正确和不正确题的比例,如正确数量20%,错误数量80%),
时间:2023年12月25日 21:46
作者:阿夏
'''import random
from win32com.client import constants,gencache
from win32com.client.gencache import EnsureDispatch
from win32com.client import constants # 导入枚举常数模块
import os,timeimport docx
from docx import Document
from docx.shared import Pt 
from docx.shared import RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qnfrom docxtpl import DocxTemplate
import pandas as pd
from docx2pdf import convert
from docx.shared import RGBColor# 第一步:制作不重复所有“+”、不重复所有减法# 不重复的数字题
num=int(input('打印几份(必须双数,根据人数,如32人)\n'))classroom=input('班级(输入中、大)\n')
bl=int(input('正确题的比例,如2,就是20%的正确题,80%的错误题\n'))
size=20
height1=11
weight1=4
gz=height1*weight1   # 115
sum1=int(input('X-Y以内的“+” 最小数字X(0)\n'))
sum2=int(input('X-Y以内的“+” 最大数字Y(0-99)\n'))# 5以内“+”题共21题
P1=[]# 正确for a in range(0,sum2+1):     # 起始数字就是10,就是排除掉0-10之间的数字for b in range(0,sum2+1):      # 起始数字为0,if 0<=a+b<sum2+1:     w=random.randint(sum1,sum2)        # 随机生成错误数字    # print('{}+{}='.format(a,b))            P1.append('{}+{}={}'.format('%02d'%a,'%02d'%b,'%02d'%(a+b)))if 0<=b+a<sum2+1:    # print('{}+{}='.format(a,b))P1.append('{}+{}={}'.format('%02d'%b,'%02d'%a,'%02d'%(a+b)))else:passP1 =list(set(P1))    # 排除重复,但随机打乱
P1.sort()    # 小到大排序
print(P1)
# 正确的答案
# ['00+00=00', '00+01=01', '00+02=02', '00+03=03', '00+04=04', '00+05=05', '01+00=01', '01+01=02', '01+02=03', '01+03=04', '01+04=05', '02+00=02', '02+01=03', '02+02=04', '02+03=05', '03+00=03', '03+01=04', '03+02=05', '04+00=04', '04+01=05', '05+00=05']# 新建一个”装N份word和PDF“的临时文件夹
imagePath1=r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\零时Word'
if not os.path.exists(imagePath1):  # 判断存放图片的文件夹是否存在os.makedirs(imagePath1)  # 若图片文件夹不存在就创建D=[]
for z in range(0,num):   #多少份  # 标题说明# 新建worddoc = Document(r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\04判断模板一页两份.docx')  for j in range(2):P2=[]# 不正确的答案随机抽取for p in P1:w=random.randint(sum1,sum2)        # 随机生成错误数字P2.append(p[0:6]+'{}'.format('%02d'%(w)))print(P2)# ['00+00=10', '00+01=10', '00+02=10', '00+03=10', '00+04=10', '00+05=10', '01+00=10', '01+01=10', '01+02=10', '01+03=10', '01+04=10', '02+00=10', '02+01=10', '02+02=10', '02+03=10', '03+00=10', '03+01=10', '03+02=10', '04+00=10', '04+01=10', '05+00=10']P3=P1+P2# [[],[]]print('P3长度{}'.format(len(P3)))# 二位数去0P4=[]for i  in P3:    # 每个内容是00+00=00,一共6个字符# print(i)if i[0]=='0'and i[3]=='0' and i[6]=='0':P4.append(i[1:3]+i[4:6]+i[7]) if i[0]=='0'and i[3]=='0'and i[6]!='0':P4.append(i[1:3]+i[4:]) if i[0]=='0'and i[3]!='0'and i[6]!='0':  P4.append(i[1:])if i[0]=='0'and i[3]!='0'and i[6]=='0':  P4.append(i[1:6]+i[7])if i[0]!='0'and i[3]=='0'and i[6]=='0': P4.append(i[0:3]+i[4:6]+i[7])if i[0]!='0'and i[3]!='0'and i[6]=='0':P4.append(i[0:6]+i[7])    if i[0]!='0'and i[3]=='0'and i[6]!='0':  P4.append(i[0:3]+i[4:])if i[0]!='0'and i[3]!='0'and i[6]!='0':P4.append(i)print(P4)print('{}-{}之间的加法判断题共有  {}  题'.format(sum1,sum2,len(P4)) )   # 42#  如果正确题+错误题大于44题P=[] if len(P4)>gz:        # 正确题在前,错误题在后P5=[]f=int(len(P4)/2)        # 21for e in range(int(len(P4)/f)):P5.append(P4[e*f:e*f+f])print(P5)# 随机抽取比例 共44题zq=int(gz*(bl*10/100))cw=gz-zq# 从P5[0]随机抽取20%, 从P5[1]随机抽取80%,组成P  a1=P5[0]a2=P5[1]t1=random.sample (a1,zq)t2=random.sample (a2,cw)for t3 in t1:P.append(t3)for t4 in t2:P.append(t4)random.shuffle(P)             # 随机打乱# 暂时不打乱if len(P4)<=gz:for t5 in P4:P.append(t5)  random.shuffle(P)             # 随机打乱         # print(P)# print('{}-{}之间的加法判断题共有  {}  题'.format(sum1,sum2,len(P)) )   # 42# 第一行的班级和项目A=[]c='{}'.format(classroom)if len(P) <=gz:title='{}-{}“+”判断{}抽{}题5:5'.format(sum1,sum2,len(P1),len(P),bl,10-bl)if len(P) >gz:title='{}-{}“+”判断{}抽{}题{}:{}'.format(sum1,sum2,len(P1),gz,bl,10-bl)d=['0003','0006']# 表格0 表格2的 03 05单元格里写入标题信息cA.append(c)A.append(title)print(A)# 制作"单元格"bg=[]for x in range(0,weight1*3,3):       # 5   #数列 先宽 后高  for y in range(1,height1+1):      #    23s1='{}{}'.format('%02d'%y,'%02d'%x)       #数列 先y 后x  bg.append(s1)   print(bg)        print(len(bg))bg.insert(0,d[1])bg.insert(0,d[0])print(bg)print(len(bg))# 如果题目总数小于155,就提取# 例如:0-5 21题,P的第一部分是21题全部,第2部分就21题里面的随机抽屉,第3部分13也是随机抽取,可能会重复PP=[]PPP=[]PP.clear()        # P.clear()if len(P)<=gz:for l in P :         # 先写入固定的21题PP.append(l)print(PP)print('第1组长度{}'.format(len(PP)))# 0-0只有1题,所以批量155次for e in range(gz):PP.append('')                # 预留一个空行做分割线v=random.sample(P,len(P))    # 从21题随机抽取不重复21for u in v:        # 遍历提取PP.append(u)        # 添加到PPPP=PP[:gz]              # 提取前55个print('把21题批量55次后,总数量  实际提取{}格{}'.format(len(PP),len(PPP)))print(PPP)else:w=random.sample(P,len(P))    # 从21题随机抽取不重复21PPP=wPPP.insert(0,title)PPP.insert(0,classroom)print(PPP)print(len(PPP))#       # 房间模板(第一个表格)要写入的门牌号列表 table = doc.tables[j]          # 表0,表2 写标题用的# 标题写入3、5单元格  for t in range(0,len(bg)):             # 0-5是最下面一行,用来写卡片数字pp=int(bg[t][0:2])     # qq=int(bg[t][2:4])k=str(PPP[t])              # 提取list图案列表里面每个图形  t=索引数字print(pp,qq,k)# 图案符号的字体、大小参数run=table.cell(pp,qq).paragraphs[0].add_run(k)    # 在单元格0,0(第1行第1列)输入第0个图图案run.font.name = '黑体'#输入时默认华文彩云字体# run.font.size = Pt(46)  #输入字体大小默认30号 换行(一页一份大卡片run.font.size = Pt(size) #是否加粗# run.font.color.rgb = RGBColor(150,150,150) #数字小,颜色深0-255run.font.color.rgb = RGBColor(150,150,150) #数字小,颜色深0-255run.bold=True# paragraph.paragraph_format.line_spacing = Pt(180) #数字段间距r = run._elementr.rPr.rFonts.set(qn('w:eastAsia'), '黑体')#将输入语句中的中文部分字体变为华文行楷table.cell(pp,qq).paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.LEFT #居中  #       
#    doc.save(r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\零时Word\{}.docx'.format('%02d'%(z+1)))#保存为XX学号的电话号码word     time.sleep(1)from docx2pdf import convert# docx 文件另存为PDF文件inputFile = r"C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word/{}.docx".format('%02d'%(z+1))# 要转换的文件:已存在outputFile = r"C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word/{}.pdf".format('%02d'%(z+1))  # 要生成的文件:不存在# 先创建 不存在的 文件f1 = open(outputFile, 'w')f1.close()# 再转换往PDF中写入内容convert(inputFile, outputFile)print('----------第4步:把都有PDF合并为一个打印用PDF------------')# 多个PDF合并(CSDN博主「红色小小螃蟹」,https://blog.csdn.net/yangcunbiao/article/details/125248205)
import os
from PyPDF2 import PdfMerger
target_path =  'C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word'
pdf_lst = [f for f in os.listdir(target_path) if f.endswith('.pdf')]
pdf_lst = [os.path.join(target_path, filename) for filename in pdf_lst]
pdf_lst.sort()
file_merger = PdfMerger()
for pdf in pdf_lst:print(pdf)file_merger.append(pdf)if len(P) <=gz:file_merger.write("C:/Users/jg2yXRZ/OneDrive/桌面/加减法/(打印合集)05(一页两份 ){}题{}-{}加法判断题打乱“+”共{}题抽{}题{}比{}({}共{}人打印{}张).pdf" .format(gz,'%02d'%sum1,'%02d'%sum2,'%03d'%len(P1),'%02d'%len(P), bl,int(10-bl),c,num,num))
else:file_merger.write("C:/Users/jg2yXRZ/OneDrive/桌面/加减法/(打印合集)05(一页两份 ){}题{}-{}加法判断题打乱“+”共{}题抽{}题{}比{}({}共{}人打印{}张).pdf".format(gz,'%02d'%sum1,'%02d'%sum2,'%03d'%len(P1),gz, bl,int(10-bl),c,num,num))
#
file_merger.close()
# doc.Close()# # print('----------第5步:删除临时文件夹------------')    
import shutil
shutil.rmtree('C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word') #递归删除文件夹,即:删除非空文件夹

存在问题:

随机生成的错误答案中也会有正确答案(随机抽取数字)。范围越小(0-5),这种情况月明显,正确数量超过21题,。后续需要设计,确保错误题答案不会有正确数字

解决

添加代码,遇到正确答案,就跳过,实现了“”每份0-10 正确题目20%=8题“”的目标

'''
X-Y 之间的所有加法题的判断题2.0(随机生成绝对错误答案,考虑正确和不正确题的比例,如正确数量20%,错误数量80%),
时间:2023年12月25日 21:46
作者:阿夏
'''import random
from win32com.client import constants,gencache
from win32com.client.gencache import EnsureDispatch
from win32com.client import constants # 导入枚举常数模块
import os,timeimport docx
from docx import Document
from docx.shared import Pt 
from docx.shared import RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qnfrom docxtpl import DocxTemplate
import pandas as pd
from docx2pdf import convert
from docx.shared import RGBColor# 第一步:制作不重复所有“+”、不重复所有减法# 不重复的数字题
num=int(input('打印几份(必须双数,根据人数,如32人)\n'))classroom=input('班级(输入中、大)\n')
bl=int(input('正确题的比例,如2,就是20%的正确题,80%的错误题\n'))
size=20
height1=11
weight1=4
gz=height1*weight1   # 115
sum1=int(input('X-Y以内的“+” 最小数字X(0)\n'))
sum2=int(input('X-Y以内的“+” 最大数字Y(0-99)\n'))# 5以内“+”题共21题
P1=[]# 正确for a in range(0,sum2+1):     # 起始数字就是10,就是排除掉0-10之间的数字for b in range(0,sum2+1):      # 起始数字为0,if 0<=a+b<sum2+1:     w=random.randint(sum1,sum2)        # 随机生成错误数字    # print('{}+{}='.format(a,b))            P1.append('{}+{}={}'.format('%02d'%a,'%02d'%b,'%02d'%(a+b)))if 0<=b+a<sum2+1:    # print('{}+{}='.format(a,b))P1.append('{}+{}={}'.format('%02d'%b,'%02d'%a,'%02d'%(a+b)))else:passP1 =list(set(P1))    # 排除重复,但随机打乱
P1.sort()    # 小到大排序
print(P1)
# 正确的答案
# ['00+00=00', '00+01=01', '00+02=02', '00+03=03', '00+04=04', '00+05=05', '01+00=01', '01+01=02', '01+02=03', '01+03=04', '01+04=05', '02+00=02', '02+01=03', '02+02=04', '02+03=05', '03+00=03', '03+01=04', '03+02=05', '04+00=04', '04+01=05', '05+00=05']# 新建一个”装N份word和PDF“的临时文件夹
imagePath1=r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\零时Word'
if not os.path.exists(imagePath1):  # 判断存放图片的文件夹是否存在os.makedirs(imagePath1)  # 若图片文件夹不存在就创建D=[]
for z in range(0,num):   #多少份  # 标题说明# 新建worddoc = Document(r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\04判断模板一页两份.docx')  for j in range(2):P2=[]# 不正确的答案随机抽取for p in P1:w=random.randint(sum1,sum2)        # 随机生成错误数字v='%02d'%w             # 错误数字变成两位数if v==p[6:]:           # 如果错误数字等于答案数字,跳过passelse:P2.append(p[0:6]+'{}'.format('%02d'%(w)))print(P2)# ['00+00=10', '00+01=10', '00+02=10', '00+03=10', '00+04=10', '00+05=10', '01+00=10', '01+01=10', '01+02=10', '01+03=10', '01+04=10', '02+00=10', '02+01=10', '02+02=10', '02+03=10', '03+00=10', '03+01=10', '03+02=10', '04+00=10', '04+01=10', '05+00=10']P3=P1+P2# [[],[]]print('P3长度{}'.format(len(P3)))# 二位数去0P4=[]for i  in P3:    # 每个内容是00+00=00,一共6个字符# print(i)if i[0]=='0'and i[3]=='0' and i[6]=='0':P4.append(i[1:3]+i[4:6]+i[7]) if i[0]=='0'and i[3]=='0'and i[6]!='0':P4.append(i[1:3]+i[4:]) if i[0]=='0'and i[3]!='0'and i[6]!='0':  P4.append(i[1:])if i[0]=='0'and i[3]!='0'and i[6]=='0':  P4.append(i[1:6]+i[7])if i[0]!='0'and i[3]=='0'and i[6]=='0': P4.append(i[0:3]+i[4:6]+i[7])if i[0]!='0'and i[3]!='0'and i[6]=='0':P4.append(i[0:6]+i[7])    if i[0]!='0'and i[3]=='0'and i[6]!='0':  P4.append(i[0:3]+i[4:])if i[0]!='0'and i[3]!='0'and i[6]!='0':P4.append(i)print(P4)print('{}-{}之间的加法判断题共有  {}  题'.format(sum1,sum2,len(P4)) )   # 42#  如果正确题+错误题大于44题P=[] if len(P4)>gz:        # 正确题在前,错误题在后P5=[]f=int(len(P4)/2)        # 21for e in range(int(len(P4)/f)):P5.append(P4[e*f:e*f+f])print(P5)# 随机抽取比例 共44题zq=int(gz*(bl*10/100))cw=gz-zq# 从P5[0]随机抽取20%, 从P5[1]随机抽取80%,组成P  a1=P5[0]a2=P5[1]t1=random.sample (a1,zq)t2=random.sample (a2,cw)for t3 in t1:P.append(t3)for t4 in t2:P.append(t4)random.shuffle(P)             # 随机打乱# 暂时不打乱if len(P4)<=gz:for t5 in P4:P.append(t5)  random.shuffle(P)             # 随机打乱         # print(P)# print('{}-{}之间的加法判断题共有  {}  题'.format(sum1,sum2,len(P)) )   # 42# 第一行的班级和项目A=[]c='{}'.format(classroom)if len(P1) <=gz:title='{}-{}“+”判断{}抽{}题5:5'.format(sum1,sum2,len(P1),len(P),bl,10-bl)if len(P1) >gz:title='{}-{}“+”判断{}抽{}题{}:{}'.format(sum1,sum2,len(P1),gz,bl,10-bl)d=['0003','0006']# 表格0 表格2的 03 05单元格里写入标题信息cA.append(c)A.append(title)print(A)# 制作"单元格"bg=[]for x in range(0,weight1*3,3):       # 5   #数列 先宽 后高  for y in range(1,height1+1):      #    23s1='{}{}'.format('%02d'%y,'%02d'%x)       #数列 先y 后x  bg.append(s1)   print(bg)        print(len(bg))bg.insert(0,d[1])bg.insert(0,d[0])print(bg)print(len(bg))# 如果题目总数小于155,就提取# 例如:0-5 21题,P的第一部分是21题全部,第2部分就21题里面的随机抽屉,第3部分13也是随机抽取,可能会重复PP=[]PPP=[]PP.clear()        # P.clear()if len(P)<=gz:for l in P :         # 先写入固定的21题PP.append(l)print(PP)print('第1组长度{}'.format(len(PP)))# 0-0只有1题,所以批量155次for e in range(gz):PP.append('')                # 预留一个空行做分割线v=random.sample(P,len(P))    # 从21题随机抽取不重复21for u in v:        # 遍历提取PP.append(u)        # 添加到PPPP=PP[:gz]              # 提取前55个print('把21题批量55次后,总数量  实际提取{}格{}'.format(len(PP),len(PPP)))print(PPP)else:w=random.sample(P,len(P))    # 从21题随机抽取不重复21PPP=wPPP.insert(0,title)PPP.insert(0,classroom)print(PPP)print(len(PPP))#       # 房间模板(第一个表格)要写入的门牌号列表 table = doc.tables[j]          # 表0,表2 写标题用的# 标题写入3、5单元格  for t in range(0,len(bg)):             # 0-5是最下面一行,用来写卡片数字pp=int(bg[t][0:2])     # qq=int(bg[t][2:4])k=str(PPP[t])              # 提取list图案列表里面每个图形  t=索引数字print(pp,qq,k)# 图案符号的字体、大小参数run=table.cell(pp,qq).paragraphs[0].add_run(k)    # 在单元格0,0(第1行第1列)输入第0个图图案run.font.name = '黑体'#输入时默认华文彩云字体# run.font.size = Pt(46)  #输入字体大小默认30号 换行(一页一份大卡片run.font.size = Pt(size) #是否加粗# run.font.color.rgb = RGBColor(150,150,150) #数字小,颜色深0-255run.font.color.rgb = RGBColor(150,150,150) #数字小,颜色深0-255run.bold=True# paragraph.paragraph_format.line_spacing = Pt(180) #数字段间距r = run._elementr.rPr.rFonts.set(qn('w:eastAsia'), '黑体')#将输入语句中的中文部分字体变为华文行楷table.cell(pp,qq).paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.LEFT #居中  #       
#    doc.save(r'C:\Users\jg2yXRZ\OneDrive\桌面\加减法\零时Word\{}.docx'.format('%02d'%(z+1)))#保存为XX学号的电话号码word     time.sleep(1)from docx2pdf import convert# docx 文件另存为PDF文件inputFile = r"C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word/{}.docx".format('%02d'%(z+1))# 要转换的文件:已存在outputFile = r"C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word/{}.pdf".format('%02d'%(z+1))  # 要生成的文件:不存在# 先创建 不存在的 文件f1 = open(outputFile, 'w')f1.close()# 再转换往PDF中写入内容convert(inputFile, outputFile)print('----------第4步:把都有PDF合并为一个打印用PDF------------')# 多个PDF合并(CSDN博主「红色小小螃蟹」,https://blog.csdn.net/yangcunbiao/article/details/125248205)
import os
from PyPDF2 import PdfMerger
target_path =  'C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word'
pdf_lst = [f for f in os.listdir(target_path) if f.endswith('.pdf')]
pdf_lst = [os.path.join(target_path, filename) for filename in pdf_lst]
pdf_lst.sort()
file_merger = PdfMerger()
for pdf in pdf_lst:print(pdf)file_merger.append(pdf)if len(P) <=gz:file_merger.write("C:/Users/jg2yXRZ/OneDrive/桌面/加减法/(打印合集)05(一页两份 ){}题{}-{}加法判断题打乱“+”共{}题抽{}题{}比{}({}共{}人打印{}张).pdf" .format(gz,'%02d'%sum1,'%02d'%sum2,'%03d'%len(P1),'%02d'%len(P), bl,int(10-bl),c,num,num))
else:file_merger.write("C:/Users/jg2yXRZ/OneDrive/桌面/加减法/(打印合集)05(一页两份 ){}题{}-{}加法判断题打乱“+”共{}题抽{}题{}比{}({}共{}人打印{}张).pdf".format(gz,'%02d'%sum1,'%02d'%sum2,'%03d'%len(P1),gz, bl,int(10-bl),c,num,num))
#
file_merger.close()
# doc.Close()# # print('----------第5步:删除临时文件夹------------')    
import shutil
shutil.rmtree('C:/Users/jg2yXRZ/OneDrive/桌面/加减法/零时Word') #递归删除文件夹,即:删除非空文件夹

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/399617.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

(原)用pixi.js 实现 方块阵点击后原地自转效果

源码 各位&#xff0c;请教一个问题&#xff0c;我这个还有BUG&#xff0c;我是想实现&#xff0c;点击一下可以 停止转动&#xff0c;然后再点一下重新转动。而不是一直加速&#xff0c;有没有什么好办法&#xff1f; PS:问题已经解决&#xff0c;谢谢评论的大神Antineutrino …

datatables 增、删、查、改

前提: datatable 定义 var table $(#example).DataTable({"ajax": "donor/book_donation_data.php",responsive: true,//data: data,columns: [{data: id},{data: donor},{data: book_name},{data: author},{data: publishing_time},{data: price},{data…

一位中国婆婆的自述[转]

小孙子Toby已经3岁了。在美国待了三个月&#xff0c;洋媳妇Susan教育孩子的方法&#xff0c;令我这个中国婆婆大开眼界。每天早上&#xff0c;Toby醒来后&#xff0c;Susan把早餐往餐桌上一放&#xff0c;就自顾自地忙去了。Toby会自己爬上凳子&#xff0c;喝牛奶&#xff0c;吃…

Webpack使用指南

Webpack 是当下最热门的前端资源模块化管理和打包工具。 什么是webpack Webpack 是当下最热门的前端资源模块化管理和打包工具。它可以将许多松散的模块按照依赖和规则打包成符合生产环境部署的前端资源。还可以将按需加载的模块进行代码分隔&#xff0c;等到实际需要的时候再异…

学习笔记找到多个具有相同 ID“_header”的控件,FindControl 要求控件具有唯一的 ID....

解决 找到多个具有相同 ID“_header”的控件,FindControl 要求控件具有唯一的 ID. private void DisplayHotBooks() { //获取所有的书分类信息 IList<Category> list CategoryManager.GetAllCategories(); int i 0; foreach (Category …

JS--数组和字典

JS--数组和字典 定义数组 var my_array new Array(); 一、JS数组 JavaScript中的数组类似于Python的列表   https://www.cnblogs.com/bigberg/p/9237856.html 1 a [11,22,33,44] 常见功能&#xff1a;  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 obj.length 数…

程序猿值得看的几个技术网站(记录)

最近发现一批很优秀的网站&#xff0c;他们有的属于个人有的属于组织&#xff0c; 但是他们网站中所记录的内容&#xff0c;可以供很多软件开发的人员学习&#xff0c;不同于国内一线的一些网站&#xff0c;这些网站所记录中的内容&#xff0c;精致&#xff0c;简洁&#xff01…

基本数据类型了解

BCD码&#xff1a; 用4位二进制数来表示1位十进制数中的0~9这10个数码&#xff0c;简称BCD码&#xff0c;即BCD代码。Binary-Coded Decima&#xff0c;简称BCD&#xff0c;称BCD码或二- 十进制代码&#xff0c;亦称二进码十进数。是一种二制的数字编码形式&#xff0c;用二进制…

wordpress去掉自带的logo或者左侧栏的菜单方法

https://www.jb51.net/cms/144566.html 去掉logo或者左侧栏的菜单&#xff0c;防止被改掉。 在使用模板下的functions.php下修改 复制代码 代码如下: function my_edit_toolbar($wp_toolbar) { $wp_toolbar->remove_node(wp-logo); //去掉Wordpress LOGO $wp_toolba…

vue-cli创建项目

vue学习资料 Vue.js官网&#xff08;https://vuejs.org.cn/&#xff09; Vue-cli (https://github.com/vuejs/vue-cli) Vue-rescource (https//github.com/vuejs/vue-rescource) Vue-router (https://github.com/vuejs/vue-router) better-scroll (https://github.com/ustbhuan…

通过webbrowser实现js与winform的相互调用

为什么80%的码农都做不了架构师&#xff1f;>>> 1客户端页面 <!DOCTYPE html><html xmlns"http://www.w3.org/1999/xhtml"> <head><meta charset"utf-8" /><title></title> </head> <body>&l…

Visual Studio 2012中使用GitHub

前言 一直以来都想使用Git来管理自己平时积累的小代码&#xff0c;就是除了工作之外的代码了。有时候自己搞个小代码&#xff0c;在公司写了&#xff0c;就要通过U盘或者网盘等等 一系列工具进行Copy&#xff0c;然后回家才能继续在原来的基础上作业。Copy来Copy去的麻烦不说&a…

JS判断字符串变量是否含有某个字串的方法

https://www.cnblogs.com/mmyh/p/6065920.html var str "abc"; if(str.indexOf("bc")>-1){ alert(str中包含bc字符串); } https://blog.csdn.net/weixin_42869591/article/details/83215144 js&#xff0c;indexOf()查找字符串&#xff0c;返回指定…

NOIP2015 D1 解题报告

T1 神奇的幻方 题目描述 幻方是一种很神奇的N*N矩阵&#xff1a;它由数字1,2,3,……,N*N构成&#xff0c;且每行、每列及两条对角线上的数字之和都相同。 当N为奇数时&#xff0c;我们可以通过以下方法构建一个幻方&#xff1a; 首先将1写在第一行的中间。 之后&#xff0c;按如…

wordpress后台添加子菜单 add_submenu_page()

https://blog.csdn.net/chaishen10000/article/details/46940257 http://yangjunwei.com/868.html

spring容器扩展功能之一:spring加载ApplicationContext.xml的四种方式

容器加载Bean的常见两个类ApplicationContext和BeanFactory&#xff0c; 一、首先&#xff0c;看看spring中加载配置在xml中的Bean对象到容器 spring 中加载xml配置文件的方式,好像有4种, xml是最常见的spring 应用系统配置源。Spring中的几种容器都支持使用xml装配bean&#x…

Linux命令简单操作之lsof

lsof lsof(list open files)是一个列出当前系统打开文件的工具 lsof语法格式&#xff1a; lsof &#xff3b;options&#xff3d; filename lsof常用命令&#xff1a; lsof -p pid 列出pid进程的所有打开的文件 lsof -c filename 列出filename程序名所打开的文件 lsof -i 列出所…

Linux内核源码分析--内核启动之(4)Image内核启动(setup_arch函数)(Linux-3.0 ARMv7)【转】...

原文地址&#xff1a;Linux内核源码分析--内核启动之(4)Image内核启动(setup_arch函数)&#xff08;Linux-3.0 ARMv7&#xff09; 作者&#xff1a;tekkamanninja 转自&#xff1a;http://blog.chinaunix.net/uid-25909619-id-4938393.html 在分析start_kernel函数的时候&#…

软工随堂练 找出和值最大的子矩阵 尹亚男 赵静娜

题目&#xff1a;从m*n矩阵中找出元素和最大的子矩阵。 分析&#xff1a;此题是可看做节课求和值最大子数组的一种延伸。但如果按之前的枚举法显然太过麻烦&#xff0c;复杂度为O&#xff08;n^4&#xff09;。那么有没有更好的方法呢&#xff1f; 我们拿出上一道题做了进一步的…

wordpress进阶教程(十九):创建自定义的找回密码页面

http://www.ashuwp.com/courses/highgrade/338.html 文章参考自&#xff1a;http://www.tutorialstag.com/wordpress-custom-password-reset-page-template.html#codesyntax_2 密码重置是一个比稍微复杂的过程&#xff0c;因为这个过程需要更多的数据。 在这篇文章之前&#…