Added style kwarg

This commit is contained in:
lukew3
2020-12-17 16:29:38 -05:00
parent 7c3d2cd5dc
commit 3fb3a07c65
3 changed files with 20 additions and 12 deletions

View File

@@ -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]

View File

@@ -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)

View File

@@ -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))