From d463bc74430a218c57205590e3b724a65c98d011 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 29 Jul 2017 20:30:44 -0400 Subject: [PATCH] Do some math practice goop --- mathpractice/mksheet.py | 100 ++++++++++++++++++++++++++++++++++++++++ mathpractice/style.css | 22 +++++++++ 2 files changed, 122 insertions(+) create mode 100644 mathpractice/mksheet.py create mode 100644 mathpractice/style.css diff --git a/mathpractice/mksheet.py b/mathpractice/mksheet.py new file mode 100644 index 0000000..91e2937 --- /dev/null +++ b/mathpractice/mksheet.py @@ -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([ + '', + '', + '', + 'MATHS', + '', + '', + '' + ]) + + +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([ + '
', + '

', + '{}'.format(f0), + '

', + '

', + 'x', + '{}'.format(f1), + '

', + '

', + '', + '

', + '
' + ]) + + +def _format_footer(): + return '' + + +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()) diff --git a/mathpractice/style.css b/mathpractice/style.css new file mode 100644 index 0000000..7b9ab04 --- /dev/null +++ b/mathpractice/style.css @@ -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; +}