mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
@@ -32,7 +32,13 @@ class Generator:
|
|||||||
) + " " + self.title + " " + self.generalProb + " " + self.generalSol
|
) + " " + self.title + " " + self.generalProb + " " + self.generalSol
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
return self.func(*args, **kwargs)
|
try:
|
||||||
|
return self.func(*args, **kwargs)
|
||||||
|
except TypeError:
|
||||||
|
# If an error is thrown from kwargs, remove the style element
|
||||||
|
# This happens if someone trys to get style='latex' for an
|
||||||
|
del kwargs['style']
|
||||||
|
return self.func(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def getGenList():
|
def getGenList():
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
def basicAlgebraFunc(maxVariable=10):
|
def basicAlgebraFunc(maxVariable=10, style='raw'):
|
||||||
a = random.randint(1, maxVariable)
|
a = random.randint(1, maxVariable)
|
||||||
b = random.randint(1, maxVariable)
|
b = random.randint(1, maxVariable)
|
||||||
c = random.randint(b, maxVariable)
|
c = random.randint(b, maxVariable)
|
||||||
@@ -20,8 +20,12 @@ def basicAlgebraFunc(maxVariable=10):
|
|||||||
elif a == 1 or a == i:
|
elif a == 1 or a == i:
|
||||||
x = f"{c - b}"
|
x = f"{c - b}"
|
||||||
|
|
||||||
problem = f"{a}x + {b} = {c}"
|
if style == 'latex':
|
||||||
solution = x
|
problem = f"\\({a}x + {b} = {c}\\)"
|
||||||
|
solution = "\\(" + x + "\\)"
|
||||||
|
else:
|
||||||
|
problem = f"{a}x + {b} = {c}"
|
||||||
|
solution = x
|
||||||
return problem, solution
|
return problem, solution
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
def logFunc(maxBase=3, maxVal=8):
|
def logFunc(maxBase=3, maxVal=8, style='raw'):
|
||||||
a = random.randint(1, maxVal)
|
a = random.randint(1, maxVal)
|
||||||
b = random.randint(2, maxBase)
|
b = random.randint(2, maxBase)
|
||||||
c = pow(b, a)
|
c = pow(b, a)
|
||||||
|
|
||||||
problem = "log" + str(b) + "(" + str(c) + ")"
|
if style == 'latex':
|
||||||
solution = str(a)
|
problem = "\\(\\log_{" + str(b) + "}" + str(c) + "\\)"
|
||||||
|
print(problem)
|
||||||
|
solution = "\\(" + str(a) + "\\)"
|
||||||
|
else:
|
||||||
|
problem = "log" + str(b) + "(" + str(c) + ")"
|
||||||
|
solution = str(a)
|
||||||
|
|
||||||
return problem, solution
|
return problem, solution
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100):
|
def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100, style='raw'):
|
||||||
a = random.randint(0, maxMatrixVal)
|
a = random.randint(0, maxMatrixVal)
|
||||||
b = random.randint(0, maxMatrixVal)
|
b = random.randint(0, maxMatrixVal)
|
||||||
c = random.randint(0, maxMatrixVal)
|
c = random.randint(0, maxMatrixVal)
|
||||||
d = random.randint(0, maxMatrixVal)
|
d = random.randint(0, maxMatrixVal)
|
||||||
|
|
||||||
constant = random.randint(0, int(maxRes / max(a, b, c, d)))
|
constant = random.randint(0, int(maxRes / max(a, b, c, d)))
|
||||||
problem = f"{constant} * [[{a}, {b}], [{c}, {d}]] = "
|
|
||||||
solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]"
|
a1 = a * constant
|
||||||
|
b1 = b * constant
|
||||||
|
c1 = c * constant
|
||||||
|
d1 = d * constant
|
||||||
|
|
||||||
|
if style == 'latex':
|
||||||
|
problem = "\\(" + str(constant) + "\\cdot\\begin{bmatrix}" + str(a) + "&" + str(b) + "\\\\" + str(c) + "&" + str(d) + "\\end{bmatrix}=\\)"
|
||||||
|
solution = "\\(\\begin{bmatrix}" + str(a1) + "&" + str(b1) + "\\\\" + str(c1) + "&" + str(d1) + "\\end{bmatrix}\\)"
|
||||||
|
else:
|
||||||
|
problem = f"{constant} * [[{a}, {b}], [{c}, {d}]] = "
|
||||||
|
solution = f"[[{a1},{b1}],[{c1},{d1}]]"
|
||||||
return problem, solution
|
return problem, solution
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
def additionFunc(maxSum=99, maxAddend=50):
|
def additionFunc(maxSum=99, maxAddend=50, style='raw'):
|
||||||
|
if maxAddend > maxSum:
|
||||||
|
maxAddend = maxSum
|
||||||
a = random.randint(0, maxAddend)
|
a = random.randint(0, maxAddend)
|
||||||
# The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
|
# The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
|
||||||
b = random.randint(0, min((maxSum - a), maxAddend))
|
b = random.randint(0, min((maxSum - a), maxAddend))
|
||||||
c = a + b
|
c = a + b
|
||||||
problem = str(a) + "+" + str(b) + "="
|
|
||||||
solution = str(c)
|
if style == 'latex':
|
||||||
return problem, solution
|
problem = "\\(" + str(a) + '+' + str(b) + "\\)"
|
||||||
|
solution = str(c)
|
||||||
|
return problem, solution
|
||||||
|
else:
|
||||||
|
problem = str(a) + "+" + str(b) + "="
|
||||||
|
solution = str(c)
|
||||||
|
return problem, solution
|
||||||
|
|
||||||
|
|
||||||
addition = Generator("Addition", 0, "a+b=", "c", additionFunc)
|
addition = Generator("Addition", 0, "a+b=", "c", additionFunc)
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ genList = getGenList()
|
|||||||
|
|
||||||
|
|
||||||
# || Non-generator Functions
|
# || Non-generator Functions
|
||||||
def genById(id):
|
def genById(id, *args, **kwargs):
|
||||||
generator = genList[id][2]
|
generator = genList[id][2]
|
||||||
return (generator())
|
return (generator(*args, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
def make_worksheet(title):
|
def make_worksheet(title):
|
||||||
|
|||||||
15
test.py
15
test.py
@@ -1,16 +1,3 @@
|
|||||||
from mathgenerator import mathgen
|
from mathgenerator import mathgen
|
||||||
|
|
||||||
# test your generators here
|
print(mathgen.genById(17, style='latex')[0])
|
||||||
|
|
||||||
# print(mathgen.addition())
|
|
||||||
|
|
||||||
# prints each generator in genList
|
|
||||||
list = mathgen.getGenList()
|
|
||||||
for item in list:
|
|
||||||
print(item[2])
|
|
||||||
|
|
||||||
# print(mathgen.getGenList())
|
|
||||||
print(mathgen.genById(10))
|
|
||||||
|
|
||||||
#Make a pdf with 10 problems of generator id 1
|
|
||||||
# mathgen.makePdf(0, 10)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user