From 09f66b3d12ce6333fd9e1a28d4c4b009558f3c14 Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Fri, 16 Oct 2020 22:47:02 +0530 Subject: [PATCH] Adding a new math function commonFactors --- mathgenerator/mathgen.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 16f7537..d725d5e 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -387,6 +387,26 @@ def primeFactors(minVal=1, maxVal=200): solution = f"{factors}" return problem, solution +def commonFactors(maxVal=100): + a = random.randint(1, maxVal) + b = random.randint(1, maxVal) + x, y = a, b + c = a * b + if (x < y): + min = x + else: + min = y + count = 0 + arr = [] + for i in range(1, min + 1): + if (x % i == 0): + if (y % i == 0): + count = count + 1 + arr.append(i) + problem = f"Common Factors of {a} and {b} = " + solution = arr + return problem, solution + # || Class Instances #Format is: @@ -419,4 +439,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) +commonFactors = Generator("Common Factors", 28, "Common Factors of {a} and {b} = ","[c, d, ...]",commonFactors) \ No newline at end of file