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
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():
correctedList = genList[-1:] + genList[:-1]

View File

@@ -1,17 +1,23 @@
from .__init__ import *
def additionFunc(maxSum=99, maxAddend=50):
print(maxSum)
def additionFunc(maxSum=99, maxAddend=50, style='raw'):
if maxAddend > maxSum:
maxAddend = maxSum
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
b = random.randint(0, min((maxSum - a), maxAddend))
c = a + b
problem = str(a) + "+" + str(b) + "="
solution = str(c)
return problem, solution
if style == 'latex':
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)