mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Update mathgen.py
Request for adding combinations function to the generator.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -420,3 +433,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)
|
||||
|
||||
Reference in New Issue
Block a user