Last active
September 16, 2021 19:22
-
-
Save ahmed4end/f4ca331cc7fc0e3f8d92fda1b5492e03 to your computer and use it in GitHub Desktop.
long division generator
This file contains 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
import random | |
dividend_length = 3 | |
divsior_length = 1 | |
integer_results = 0 | |
short_float = 1 | |
pop = 20 | |
_c, res = 0, [] | |
while len(res)<pop and _c<5000: | |
_c += 1 | |
a = random.randint(int('9'*(dividend_length-1) or '0')+1, int('9'*dividend_length)) | |
b = random.randint(int('9'*(divsior_length-1) or '0')+1, int('9'*divsior_length)) | |
if b==1 or (a)<=(b*12) or a%11==0:continue # filter | |
if integer_results & (a/b).is_integer(): | |
res.append(f'{a//b}={b}÷{a}') | |
elif not integer_results and not (a/b).is_integer(): | |
if short_float and len(str((a/b)%1))<=5: | |
res.append(f'{a/b}={b}÷{a}') | |
elif not short_float: | |
res.append(f'{a/b}={b}÷{a}') | |
row_count = 6 | |
while len(res)%6!=0: | |
res.append('') | |
pop = iter(res) | |
for i in zip(*(pop,)*row_count): | |
for j in i: | |
print(str(j).rjust(20, ' '), end=' ') | |
print() | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment