Created
April 7, 2014 12:30
-
-
Save longarm/10019408 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# description: generate a series of arithmetic for teaching | |
# TODO | |
import os | |
import sys | |
import random | |
import string | |
def generater(rang): | |
a = ('+', '-') | |
width = len(str(rang)) | |
op1 = random.randint(0, rang) | |
op2 = random.randint(0, rang) | |
op = random.randint(0, 1) | |
if op == 1 and op1 < op2: | |
op1, op2 = op2, op1 | |
return string.join((string.rjust(str(op1), width), | |
a[op], | |
string.rjust(str(op2), width), | |
'='), ' ') | |
def format(s): | |
str = '' | |
for ss in s: | |
str += string.ljust(ss, 20) | |
str += '\n' | |
return str | |
def main(): | |
count = 100 | |
rang = 100 | |
step = 4 | |
r = open("test.txt", 'w') | |
for index in range(0, count, step): | |
exp = [] | |
for x in range(0, step): | |
exp.append(generater(rang)) | |
r.write(format(exp)) | |
r.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment