mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
Added style kwarg
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user