娃上 一年级了,要开始学计算了,网上找的题目生成器都有点问题,因为是计算结果是10以内,而不是选的数字是10以内的加减法。
就自己写了一个,比较粗糙啊,不过可以改改后续,比如生成20以内的,100以内的,都可以的。
娃不容易,做父母的也不容易啊。
[Python] 纯文本查看 复制代码 import random
import xlrd
import xlwt
import os
filename = 'count10.xls' #检测当前目录下是否有count10.xls文件,如果有则清除以前保存文件
if os.path.exists(filename):
os.remove(filename)
book=xlwt.Workbook(encoding='utf-8',style_compression=0)
sheet1=book.add_sheet('10以内加减法',cell_overwrite_ok=True)
style = xlwt.XFStyle()#格式信息
font = xlwt.Font()#字体基本设置
font.name = u'Times New Roman'
font.color = 'black'
font.height= 360 #字体大小,18 号字体
style.font = font
alignment = xlwt.Alignment() # 设置字体在单元格的位置
alignment.horz = xlwt.Alignment.HORZ_CENTER #水平方向
alignment.vert = xlwt.Alignment.VERT_CENTER #竖直方向
#调整下excel表的格式
sheet1.col(1).width = 256 * 3
sheet1.col(2).width = 256 * 3
sheet1.col(3).width = 256 * 3
sheet1.col(4).width = 256 * 3
sheet1.col(5).width = 256 * 6
sheet1.col(6).width = 256 * 3
sheet1.col(7).width = 256 * 3
sheet1.col(8).width = 256 * 3
sheet1.col(9).width = 256 * 3
sheet1.col(10).width = 256 * 6
sheet1.col(11).width = 256 * 3
sheet1.col(12).width = 256 * 3
sheet1.col(13).width = 256 * 3
sheet1.col(14).width = 256 * 3
sheet1.col(15).width = 256 * 6
sheet1.col(16).width = 256 * 3
sheet1.col(17).width = 256 * 3
sheet1.col(18).width = 256 * 3
sheet1.col(19).width = 256 * 3
sheet1.col(20).width = 256 * 6
sheet1.col(21).width = 256 * 3
sheet1.col(22).width = 256 * 3
sheet1.col(23).width = 256 * 3
sheet1.col(24).width = 256 * 3
sheet1.col(25).width = 256 * 6
for j in range(1,42,2):
for i in range(0,5):
symbol = random.choice(['+', '-']) # 随机加减
a = random.randint(1, 9) # 随机取整数
if symbol == '+':
count_resutl = random.randint(a, 10) # 随机生成计算结果
b = count_resutl - a
print(str(a) +"+"+str(b) + "=" + str(count_resutl))
sheet1.write(j,i*5+1,str(a),style)
sheet1.write(j,i*5+2,"+",style)
sheet1.write(j,i*5+3,str(b),style)
sheet1.write(j,i*5+4,"=",style)
if symbol == '-':
b = random.randint(0, a)
count_resutl = a - b
print(str(a) + "-" + str(b) + "=")
sheet1.write(j, i*5+1, str(a),style)
sheet1.write(j, i*5+2, "-",style)
sheet1.write(j, i*5+3, str(b),style)
sheet1.write(j, i*5+4, "=",style)
savepath='count10.xls'
book.save(savepath)
|