我给我小孩写了个100内加减法的,应同事要求,顺手整了个99乘法的
功能很简单,生成一个练习99乘法的excel文件,直接打出来给小孩做就行
效果如图:
源码附上
[Python] 纯文本查看 复制代码 import random
import xlrd
import xlwt
from xlutils.copy import copy
class Subject(object):
"""docstring for Subject"""
def __init__(self, min_num, max_num):
self.min_num = min_num
self.max_num = max_num
def random(self):
while True:
num_1 = random.randint(self.min_num,self.max_num)
num_2 = random.randint(self.min_num,self.max_num)
res = num_1 * num_2
blank = random.randint(1, 3)
if blank == 1:
return("( )"+"×"+str(num_2)+"="+str(res))
if blank == 2:
return(str(num_1)+"×"+"( )"+"="+str(res))
else:
return(str(num_1)+"×"+str(num_2)+"="+"( )")
class Intoexcel(object):
"""docstring for Intoexcel"""
def __init__(self, xl_x, xl_y, content):
self.x = xl_x
self.y = xl_y
self.content = content
def write(self):
workbook = xlwt.Workbook()
sheet = workbook.add_sheet('test1')
style = xlwt.XFStyle()
font = xlwt.Font()
font.height = 20*20
alignment = xlwt.Alignment()
alignment.horz = 0x01
alignment.vert = 0x01
style = xlwt.XFStyle()
style.font = font
style.alignment = alignment
borders = xlwt.Borders()
borders.bottom = xlwt.Borders.THIN
style.borders = borders
row_sheet = 0
col_sheet = 0
for row_sheet in range(self.content):
for col_sheet in range(5):
a = Subject(self.x, self.y)
sub = a.random()
sheet.col(col_sheet).width = 256*19
tall_style = xlwt.easyxf('font:height 620;')
first_row = sheet.row(row_sheet)
first_row.set_style(tall_style)
sheet.write(row_sheet, col_sheet, sub, style)
workbook.save('99乘法填空.xls')
if __name__ == '__main__':
min_num = 1 # 最小数
max_num = 9 # 最大数
sub_num = 100 # 多少行
sub= Intoexcel(min_num, max_num, sub_num)
sub.write()
链接:https://pan.baidu.com/s/1rG4JlbdMPI98pb5VoplZYw
提取码:el3j |