⼀个从题库⾥⾃动⽣成word试卷的⼩程序⼀个从题库⾥⾃动⽣成word试卷的⼩程序
import random
小程序开发一键生成平台源码from docx import Document
from docx.shared import Inches
um.section import WD_ORIENT, WD_SECTION
l.ns import qn
def getRandList(max, size):
newList =[]
while(len(newList)< size):
ran = random.randrange(max)
unt(ran)==0):
newList.append(ran)
return newList
选择题数量=25
填空题数量=10
file=open("./p1.txt","r+", encoding='utf8')
myStr =ad()
file.close()
file=open("./p2.txt","r+", encoding='utf8')
myStr2 =ad()
file.close()
p1_list = myStr.split("\n")
p2_list = myStr2.split("\n")
for temp in range(100):
p1_out = getRandList(len(p1_list),选择题数量)
p2_out = getRandList(len(p2_list),填空题数量)
output ="⼀、填空题(共{0}题,每题2分)\n".format(选择题数量)
i =1
for index in p1_out:
output +=str(i)+"、"+p1_list[index]+"\n"
i +=1
output +="\n⼆、简答题(共{0}题,每题5分)\n".format(填空题数量)
i =1
for index in p2_out:
output +=str(i)+"、"+p2_list[index]+"\n"
i +=1
output = place(" ","_")
document = Document()
document.styles['Normal'].font.name = u'宋体'
document.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
paragraph = document.add_paragraph(output)
document.save('d:/试卷/试卷{0}.docx'.format(temp))
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论