From 78d6bcc9b30866bfddb8e8a208c27c94aa3ef50e Mon Sep 17 00:00:00 2001 From: Rodolfo Nei Date: Fri, 16 Oct 2020 12:14:07 -0300 Subject: [PATCH 1/6] add the multiplication of fractions function --- mathgenerator/mathgen.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 16f7537..35c3e28 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -387,6 +387,29 @@ def primeFactors(minVal=1, maxVal=200): solution = f"{factors}" return problem, solution +def multiplyFractionsFunc(maxVal=10): + a = random.randint(1, maxVal) + b = random.randint(1, maxVal) + c = random.randint(1, maxVal) + d = random.randint(1, maxVal) + while (a == b): + b = 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 * c + tmp_d = b * d + 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}" + problem = f"({a}/{b})*({c}/{d})" + solution = x + return problem, solution + # || Class Instances #Format is: @@ -419,4 +442,5 @@ systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y distance2Point = Generator("Distance between 2 points", 24, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPointsFunc) pythagoreanTheorem = Generator("Pythagorean Theorem", 25, "The hypotenuse of a right triangle given the other two lengths a and b = ", "hypotenuse", pythagoreanTheoremFunc) linearEquations = Generator("Linear Equations", 26, "2x+5y=20 & 3x+6y=12", "x=-20 & y=12", linearEquationsFunc) #This has multiple variables whereas #23 has only x and y -primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) \ No newline at end of file +primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) +fractionMultiplication = Generator("Fraction Multiplication", 28, "(a/b)*(c/d)=", "x/y", multiplyFractionsFunc) \ No newline at end of file From 7c352da6a272d6a6bf9d9936290c2890569af57d Mon Sep 17 00:00:00 2001 From: Yash Date: Fri, 16 Oct 2020 21:17:54 +0530 Subject: [PATCH 2/6] added function --- mathgenerator/mathgen.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 16f7537..f63415b 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -387,6 +387,13 @@ def primeFactors(minVal=1, maxVal=200): solution = f"{factors}" return problem, solution +def regularPolygonAngle(minVal = 3,maxVal = 20): + sideNum = random.randint(minVal, maxVal) + problem = f"Find the angle of a regular polygon with {sideNum} sides" + exteriorAngle = (360/sideNum) + solution = 180 - exteriorAngle + return problem, solution + # || Class Instances #Format is: From 8a9912e40a6183e64714b02f6b3dd701ab179975 Mon Sep 17 00:00:00 2001 From: Yash Date: Fri, 16 Oct 2020 21:21:59 +0530 Subject: [PATCH 3/6] added class instance --- mathgenerator/mathgen.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index f63415b..87864c0 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -426,4 +426,5 @@ systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y distance2Point = Generator("Distance between 2 points", 24, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPointsFunc) pythagoreanTheorem = Generator("Pythagorean Theorem", 25, "The hypotenuse of a right triangle given the other two lengths a and b = ", "hypotenuse", pythagoreanTheoremFunc) linearEquations = Generator("Linear Equations", 26, "2x+5y=20 & 3x+6y=12", "x=-20 & y=12", linearEquationsFunc) #This has multiple variables whereas #23 has only x and y -primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) \ No newline at end of file +primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) +angleRegularPolygon = Generator("Angle of a Regular Polygon",28,"Find the angle of a regular polygon with 6 sides",120,regularPolygonAngle) \ No newline at end of file From 4b3874cc74003e42e9652dfc4fde5194e2357efb Mon Sep 17 00:00:00 2001 From: Yash Date: Fri, 16 Oct 2020 21:28:54 +0530 Subject: [PATCH 4/6] Rounded to 2 decimal places --- mathgenerator/mathgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 87864c0..a29b443 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -390,7 +390,7 @@ def primeFactors(minVal=1, maxVal=200): def regularPolygonAngle(minVal = 3,maxVal = 20): sideNum = random.randint(minVal, maxVal) problem = f"Find the angle of a regular polygon with {sideNum} sides" - exteriorAngle = (360/sideNum) + exteriorAngle = round((360/sideNum),2) solution = 180 - exteriorAngle return problem, solution From 4e80e009209d02b5c78cc5ddbb2933a7e41bbbea Mon Sep 17 00:00:00 2001 From: Ritu Raj <68614399+Ritu1611@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:28:04 +0530 Subject: [PATCH 5/6] Update mathgen.py Request for adding combinations function to the generator. --- mathgenerator/mathgen.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 16f7537..1f24f7e 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -386,6 +386,19 @@ def primeFactors(minVal=1, maxVal=200): problem = f"Find prime factors of {a}" solution = f"{factors}" return problem, solution +def combination(maxlength=20): + def factorial(a): + d=1 + for i in range(a): + a=(i+1)*d + d=a + return d + a= random.randint(10,maxlength) + b=random.randint(0,9) + solution= int(factorial(a)/(factorial(b)*factorial(a-b))) + problem= "Number of combinations from {} objects picked {} at a time ".format(a,b) + + return problem, solution # || Class Instances @@ -419,4 +432,5 @@ systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y distance2Point = Generator("Distance between 2 points", 24, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPointsFunc) pythagoreanTheorem = Generator("Pythagorean Theorem", 25, "The hypotenuse of a right triangle given the other two lengths a and b = ", "hypotenuse", pythagoreanTheoremFunc) linearEquations = Generator("Linear Equations", 26, "2x+5y=20 & 3x+6y=12", "x=-20 & y=12", linearEquationsFunc) #This has multiple variables whereas #23 has only x and y -primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) \ No newline at end of file +primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) +combinations=Generator("Combinations of Objects",28, "Combinations available for picking 4 objects at a time from 6 distinct objects ="," 15", combinations) From 5c79fef2fbcf711817a911a58a0f29c85a692386 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Fri, 16 Oct 2020 13:17:01 -0400 Subject: [PATCH 6/6] Update mathgen.py --- mathgenerator/mathgen.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 1f24f7e..24eb9bc 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -386,7 +386,8 @@ def primeFactors(minVal=1, maxVal=200): problem = f"Find prime factors of {a}" solution = f"{factors}" return problem, solution -def combination(maxlength=20): + +def combinationsFunc(maxlength=20): def factorial(a): d=1 for i in range(a): @@ -433,4 +434,4 @@ distance2Point = Generator("Distance between 2 points", 24, "Find the distance b pythagoreanTheorem = Generator("Pythagorean Theorem", 25, "The hypotenuse of a right triangle given the other two lengths a and b = ", "hypotenuse", pythagoreanTheoremFunc) linearEquations = Generator("Linear Equations", 26, "2x+5y=20 & 3x+6y=12", "x=-20 & y=12", linearEquationsFunc) #This has multiple variables whereas #23 has only x and y primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, c, d, ...]", primeFactors) -combinations=Generator("Combinations of Objects",28, "Combinations available for picking 4 objects at a time from 6 distinct objects ="," 15", combinations) +combinations = Generator("Combinations of Objects",28, "Combinations available for picking 4 objects at a time from 6 distinct objects ="," 15", combinationsFunc)