2013/11/14

My girl's math home work

Here is the python script to generate it, she must hate to have a father as a programmer.
from random import *
str_header = '<!DOCTYPE html><head><style>body {font-size:20pt}</style></head><html><body><pre>'
body = ""
for x in range (500):
num1 = randint(2, 99)
num2 = randint(0, num1)
body = body + " {0:3d} - {1:3d} = ".format(num1, num2)
if (x % 2) == 1:
body = body + "\n"
str_footer = "</pre></body></html>"
f = open("yuhan_math_minus.html", "w")
f.write(str_header + body + str_footer)
view raw baby_math_minus hosted with ❤ by GitHub
from random import *
str_header = '<!DOCTYPE html><head><style>body {font-size:20pt}</style></head><html><body><pre>'
body = ""
for x in range (1000):
num1 = randint(0, 99)
num2 = randint(0, 120 - num1)
body = body + " {0:3d} + {1:3d} = ".format(num1, num2)
if (x % 2) == 1:
body = body + "\n"
str_footer = "</pre></body></html>"
f = open("yuhan_math_plus.html", "w")
f.write(str_header + body + str_footer)
view raw baby_math_plus hosted with ❤ by GitHub

No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...