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 1/2] 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) From 99bbce153b8430edc186614582e2fdb5d6aa0e68 Mon Sep 17 00:00:00 2001 From: Gokul <43350089+gokulp01@users.noreply.github.com> Date: Thu, 15 Oct 2020 19:45:13 +0530 Subject: [PATCH 2/2] Added Binary to Decimal Generator --- mathgenerator/mathgen.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 7c3f858..9ae686a 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -157,13 +157,22 @@ def divisionToIntFunc(maxA=25, maxB=25): solution=int(divisor/dividend) return problem,solution -def decimalToBinary(max_dec=99): +def DecimalToBinary(max_dec=99): a = random.randint(1, max_dec) b = bin(a).replace("0b", "") problem = "Binary of "+str(a)+"=" solution = str(b) return problem, solution +def BinaryToDecimal(max_dig=10): + problem='' + for i in range(random.randint(1,max_dig)): + temp = str(random.randint(0, 1)) + problem += temp + + solution=int(problem, 2); + return problem, solution + # || Class Instances #Format is: @@ -182,4 +191,5 @@ gcd = Generator("Gcd_generator", 12, "GCD of a and b = ", "c", gcdFunc) basicAlgebra = Generator("Basic_Algebra", 13, "ax + b = c", "d", basicAlgebraFunc) 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) +decimaltobinary = Generator("Decimal to Binary",15,"Binary of a=","b",DecimalToBinary) +binarytodecimal = Generator("Decimal to Binary",16,"Decimal of a=","b",BinaryToDecimal)