From b675893fbfe30f73e5330432e625b9cb96ca2c7b Mon Sep 17 00:00:00 2001 From: Ganesh Futane <63470761+ganesh003@users.noreply.github.com> Date: Thu, 15 Oct 2020 19:24:18 +0530 Subject: [PATCH] Added Fraction Division Function --- mathgenerator/mathgen.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 7c3f858..2fc7e3c 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -164,6 +164,31 @@ def decimalToBinary(max_dec=99): solution = str(b) return problem, solution +def divideFractionsFunc(maxVal=10): + a = random.randint(1, maxVal) + b = random.randint(1, maxVal) + while (a == b): + b = random.randint(1, maxVal) + c = random.randint(1, maxVal) + d = random.randint(1, maxVal) + while (c == d): + d = random.randint(1, maxVal) + def calculate_gcd(x, y): + while(y): + x, y = y, x % y + return x + tmp_n = a * d + tmp_d = b * c + gcd = calculate_gcd(tmp_n, tmp_d) + x = f"{tmp_n//gcd}/{tmp_d//gcd}" + if (tmp_d == 1 or tmp_d == gcd): + x = f"{tmp_n//gcd}" + # for equal numerator and denominators + problem = f"({a}/{b})/({c}/{d})" + solution = x + return problem, solution + + # || Class Instances #Format is: @@ -183,3 +208,4 @@ basicAlgebra = Generator("Basic_Algebra", 13, "ax + b = c", "d", basicAlgebraFun log = Generator("Logarithm", 13, "log2(8)", "3", logFunc) intdivision = Generator("Easy Divisio",14,"a/b=","c",divisionToIntFunc) decimaltobinary = Generator("Decimal to Binary",15,"Binary of a=","b",decimalToBinary) +fractionDivision = Generator("Fraction Division", 16, "(a/b)/(c/d)=", "x/y", divideFractionsFunc)