mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Added style kwarg
This commit is contained in:
@@ -32,8 +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():
|
||||||
correctedList = genList[-1:] + genList[:-1]
|
correctedList = genList[-1:] + genList[:-1]
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
def additionFunc(maxSum=99, maxAddend=50):
|
def additionFunc(maxSum=99, maxAddend=50, style='raw'):
|
||||||
print(maxSum)
|
|
||||||
if maxAddend > maxSum:
|
if maxAddend > maxSum:
|
||||||
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)
|
||||||
|
|||||||
7
test.py
7
test.py
@@ -10,9 +10,6 @@ from mathgenerator import mathgen
|
|||||||
# print(item[2])
|
# print(item[2])
|
||||||
|
|
||||||
# print(mathgen.getGenList())
|
# print(mathgen.getGenList())
|
||||||
#print(mathgen.genById(10))
|
|
||||||
|
|
||||||
#Make a pdf with 10 problems of generator id 1
|
print(mathgen.genById(0, maxSum=20, style='latex')[0])
|
||||||
# mathgen.makePdf(0, 10)
|
print(mathgen.genById(1, style='latex'))
|
||||||
|
|
||||||
print(mathgen.genById(0, maxSum=20))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user