Last active
March 2, 2016 10:58
-
-
Save greenkey/5261cc6ccc4699e95841 to your computer and use it in GitHub Desktop.
To help my daughters learn fractions, I made an exercise generator. Now they hate me.
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
#!/usr/bin/python3 | |
from random import randrange, random | |
from fractions import Fraction | |
from functools import reduce | |
from operator import mul | |
def pf(f): | |
'''Pretty print the fraction''' | |
return "{}/{}".format(f.numerator,f.denominator) | |
while True: | |
fractions = [Fraction( randrange(1,30), randrange(1,30) ) for i in range(randrange(2,6))] | |
final = reduce(mul, fractions) | |
if final.denominator <= 30: | |
print("{} = {}".format(" x ".join([pf(f) for f in fractions]),pf(final))) | |
input() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment