From 358a676dba20345dff3eda4bc5faf066aad500e7 Mon Sep 17 00:00:00 2001 From: adityapanchal10 Date: Fri, 16 Oct 2020 22:37:17 +0530 Subject: [PATCH 1/2] added factorial function --- mathgenerator/mathgen.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 16f7537..7b648f4 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -387,6 +387,21 @@ def primeFactors(minVal=1, maxVal=200): solution = f"{factors}" return problem, solution +def factorialFunc(maxInput = 6): + a = random.randint(0, maxInput) + n = a + problem = str(a) + "! = " + b = 1 + if a == 1: + solution = str(b) + return problem, solution + else: + while n > 0: + b *= n + n = n - 1 + solution = str(b) + return problem, solution + # || Class Instances #Format is: @@ -419,4 +434,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) +factorial = Generator("Factorial", 28, "a! = ", "b", factorialFunc) \ No newline at end of file From 81602ca484e0d94ace5c967260dbaac1b545e912 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Fri, 16 Oct 2020 13:21:03 -0400 Subject: [PATCH 2/2] Update mathgen.py --- mathgenerator/mathgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 600311e..fbaf400 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -483,4 +483,4 @@ primeFactors = Generator("Prime Factorisation", 27, "Prime Factors of a =", "[b, fractionMultiplication = Generator("Fraction Multiplication", 28, "(a/b)*(c/d)=", "x/y", multiplyFractionsFunc) angleRegularPolygon = Generator("Angle of a Regular Polygon",29,"Find the angle of a regular polygon with 6 sides","120",regularPolygonAngleFunc) combinations = Generator("Combinations of Objects",30, "Combinations available for picking 4 objects at a time from 6 distinct objects ="," 15", combinationsFunc) -factorial = Generator("Factorial", 28, "a! = ", "b", factorialFunc) +factorial = Generator("Factorial", 31, "a! = ", "b", factorialFunc)