日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python十以内加减法_python生成PDF文件20以内加减法,给上小学的宝宝

發布時間:2024/1/1 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python十以内加减法_python生成PDF文件20以内加减法,给上小学的宝宝 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# -*- coding: utf-8 -*-

import random

from reportlab import platypus

from reportlab.lib.units import inch

from reportlab.lib.pagesizes import A4, landscape #最后生成橫向打印的PDF

from reportlab.lib import colors

def genList():

ret = set()

while True:

a = random.randint(1, 20)

b = random.randint(1, 20)

c = random.randint(1, 20)

if a + b + c <= 20 and (a > 10 or b > 10 or c > 10):

ret.add( '%-2d + %-2d + %-2d =' % (a, b, c) )

if len(ret) == 25: break

while True:

a = random.randint(1, 20)

b = random.randint(1, 20)

c = random.randint(1, 20)

if a + b <= 20 and a + b - c >= 0 and (a > 10 or b > 10 or c > 10):

ret.add( '%-2d + %-2d - %-2d =' % (a, b, c) )

if len(ret) == 50: break

while True:

a = random.randint(1, 20)

b = random.randint(1, 20)

c = random.randint(1, 20)

if a - b >= 0 and a - b + c <= 20 and (a > 10 or b > 10 or c > 10):

ret.add( '%-2d - %-2d + %-2d =' % (a, b, c) )

if len(ret) == 75: break

while True:

a = random.randint(11, 20)

b = random.randint(1, 20)

c = random.randint(1, 20)

if a - b - c >= 0 and (a > 10 or b > 10 or c > 10):

ret.add( '%-2d - %-2d - %-2d =' % (a, b, c) )

if len(ret) == 100: break

ret = list(ret)

random.shuffle(ret)

return ret

'''for i in genList():

print i'''

def genTable():

data = []

items = genList()

for i in range(0, len(items), 5):

data.append(items[i:i+5])

# Courier 是 reportlab 缺省定義的等寬字體

# (0,0)/(-1,-1)說的是style運用范圍,從左上到右下

tablestyle = [('FONT', (0,0), (-1,-1), 'Courier', 12),

('LINEAFTER', (0,0), (-2,-1), 1, colors.black)]

return platypus.Table(data, 2.2*inch, 0.35*inch, tablestyle)

import sys

try:

n = int(sys.argv[1]) #恩恩,生成一個多頁的PDF

except:

n = 1

try:

fname = sys.argv[2]

except:

fname = '20plus100.pdf'

doc = platypus.SimpleDocTemplate(fname, topMargin=0.5*inch, bottomMargin=0.5*inch, title='DaDa Math', author='qyb')

elements = []

for i in range(n):

elements.append(genTable())

elements.append(platypus.flowables.PageBreak())

doc.pagesize = landscape(A4)

doc.build(elements)

這個 功能需要用到python? 的reportlab? 包,,請下載安裝

分享到:

2009-12-24 16:00

瀏覽 3765

評論

總結

以上是生活随笔為你收集整理的python十以内加减法_python生成PDF文件20以内加减法,给上小学的宝宝的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。