Update mathgen.py

Adding a function for getting factorial of a random integer.
This commit is contained in:
Ritu Raj
2020-10-16 21:48:41 +05:30
committed by GitHub
parent c0f2c9b281
commit de2bf981b5

View File

@@ -386,6 +386,16 @@ def primeFactors(minVal=1, maxVal=200):
problem = f"Find prime factors of {a}"
solution = f"{factors}"
return problem, solution
def factorial(maxlength=10):
a=random.randint(0,maxlength)
d=1
problem=a
for i in range(a):
a=(i+1)*d
d=a
solution=d
return " The Factorial for {} is {} ".format(problem, solution)
# || Class Instances
@@ -420,3 +430,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)
factorials = Generator("Factorials", 28, "Factorial of a = ", "xyz", factorial)