Do some math practice goop
This commit is contained in:
parent
51a91228ca
commit
d463bc7443
100
mathpractice/mksheet.py
Normal file
100
mathpractice/mksheet.py
Normal file
@ -0,0 +1,100 @@
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
|
||||
|
||||
def main(sysargs=sys.argv[:]):
|
||||
lowest_factor = 0
|
||||
highest_factor = 15
|
||||
total = 100
|
||||
|
||||
if '-h' in sysargs or '--help' in sysargs:
|
||||
return _help(sysargs=sysargs)
|
||||
|
||||
if len(sysargs) > 1:
|
||||
lowest_factor = int(sysargs[1])
|
||||
if len(sysargs) > 2:
|
||||
highest_factor = int(sysargs[2])
|
||||
if len(sysargs) > 3:
|
||||
total = int(sysargs[3])
|
||||
|
||||
_mksheet(lowest_factor, highest_factor, total=total)
|
||||
return 0
|
||||
|
||||
|
||||
def _mksheet(lowest_factor, highest_factor, out=sys.stdout, total=100):
|
||||
gen = [_format_header()]
|
||||
|
||||
for f0, f1 in _generate_matrix(lowest_factor, highest_factor, total=total):
|
||||
gen.append(_format_pair(f0, f1))
|
||||
|
||||
gen.append(_format_footer())
|
||||
out.write('\n'.join(gen))
|
||||
out.write('\n')
|
||||
|
||||
|
||||
def _generate_matrix(lowest_factor, highest_factor, total=100):
|
||||
gen = []
|
||||
for f0 in range(lowest_factor, highest_factor):
|
||||
for f1 in range(lowest_factor, highest_factor):
|
||||
gen.append((f0, f1))
|
||||
random.shuffle(gen)
|
||||
return gen
|
||||
|
||||
|
||||
def _format_header():
|
||||
return '\n'.join([
|
||||
'<!DOCTYPE html>',
|
||||
'<html>',
|
||||
'<head>',
|
||||
'<title>MATHS</title>',
|
||||
'<style type="text/css">',
|
||||
_format_css(),
|
||||
'</style>',
|
||||
'</head>',
|
||||
'<body>'
|
||||
])
|
||||
|
||||
|
||||
def _format_css():
|
||||
style_css = os.path.join(
|
||||
os.path.abspath(os.path.dirname(__file__)),
|
||||
'style.css'
|
||||
)
|
||||
with open(style_css) as out:
|
||||
return out.read()
|
||||
|
||||
|
||||
def _format_pair(f0, f1):
|
||||
return '\n'.join([
|
||||
'<div class="ex">',
|
||||
'<p>',
|
||||
'<span class="fac">{}</span>'.format(f0),
|
||||
'</p>',
|
||||
'<p class="eq">',
|
||||
'<span class="op">x</span>',
|
||||
'<span class="fac">{}</span>'.format(f1),
|
||||
'</p>',
|
||||
'<p>',
|
||||
'<span class="ans"></span>',
|
||||
'</p>',
|
||||
'</div>'
|
||||
])
|
||||
|
||||
|
||||
def _format_footer():
|
||||
return '</body></html>'
|
||||
|
||||
|
||||
def _help(sysargs=sys.argv[:], out=sys.stdout):
|
||||
from textwrap import dedent
|
||||
out.write(dedent("""\
|
||||
Usage: {} [lowest-factor] [highest-factor]
|
||||
|
||||
Generate some math practice HTML.
|
||||
""".format(sysargs[0])))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
22
mathpractice/style.css
Normal file
22
mathpractice/style.css
Normal file
@ -0,0 +1,22 @@
|
||||
body {
|
||||
color: black;
|
||||
font-size: 18px;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.ex {
|
||||
display: inline;
|
||||
text-align: right;
|
||||
padding: 3px;
|
||||
margin: 24px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.op {
|
||||
padding-right: 18px;
|
||||
}
|
||||
|
||||
.eq {
|
||||
min-width: 48px;
|
||||
border-bottom: 1px solid black;
|
||||
}
|
Loading…
Reference in New Issue
Block a user