From 7c3d2cd5dc8401e645e4b0e06620d684171f7ccd Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 14:53:12 -0500 Subject: [PATCH 1/7] Fix genById missing args/kwargs --- mathgenerator/funcs/basic_math/addition.py | 3 +++ mathgenerator/mathgen.py | 4 ++-- test.py | 10 ++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mathgenerator/funcs/basic_math/addition.py b/mathgenerator/funcs/basic_math/addition.py index cab6dac..561c9ce 100644 --- a/mathgenerator/funcs/basic_math/addition.py +++ b/mathgenerator/funcs/basic_math/addition.py @@ -2,6 +2,9 @@ from .__init__ import * def additionFunc(maxSum=99, maxAddend=50): + print(maxSum) + 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)) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index af26ac4..55c1839 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -6,9 +6,9 @@ genList = getGenList() # || Non-generator Functions -def genById(id): +def genById(id, *args, **kwargs): generator = genList[id][2] - return (generator()) + return (generator(*args, **kwargs)) def make_worksheet(title): diff --git a/test.py b/test.py index 2c51d56..a29b04c 100644 --- a/test.py +++ b/test.py @@ -5,12 +5,14 @@ from mathgenerator import mathgen # print(mathgen.addition()) # prints each generator in genList -list = mathgen.getGenList() -for item in list: - print(item[2]) +# list = mathgen.getGenList() +#for item in list: +# print(item[2]) # print(mathgen.getGenList()) -print(mathgen.genById(10)) +#print(mathgen.genById(10)) #Make a pdf with 10 problems of generator id 1 # mathgen.makePdf(0, 10) + +print(mathgen.genById(0, maxSum=20)) From 3fb3a07c65ce89396586efa657208a2f981da64d Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 16:29:38 -0500 Subject: [PATCH 2/7] Added style kwarg --- mathgenerator/__init__.py | 9 +++++++-- mathgenerator/funcs/basic_math/addition.py | 16 +++++++++++----- test.py | 7 ++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mathgenerator/__init__.py b/mathgenerator/__init__.py index cb899b3..2b69d24 100644 --- a/mathgenerator/__init__.py +++ b/mathgenerator/__init__.py @@ -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] diff --git a/mathgenerator/funcs/basic_math/addition.py b/mathgenerator/funcs/basic_math/addition.py index 561c9ce..0cd7f61 100644 --- a/mathgenerator/funcs/basic_math/addition.py +++ b/mathgenerator/funcs/basic_math/addition.py @@ -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) diff --git a/test.py b/test.py index a29b04c..33ca0af 100644 --- a/test.py +++ b/test.py @@ -10,9 +10,6 @@ from mathgenerator import mathgen # print(item[2]) # print(mathgen.getGenList()) -#print(mathgen.genById(10)) -#Make a pdf with 10 problems of generator id 1 -# mathgen.makePdf(0, 10) - -print(mathgen.genById(0, maxSum=20)) +print(mathgen.genById(0, maxSum=20, style='latex')[0]) +print(mathgen.genById(1, style='latex')) From c0d2a2755c4f72738360030f0d7c2b941f61e8a1 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 18:58:01 -0500 Subject: [PATCH 3/7] Added latex for 11, 12, and 17. First 3 of algebra section --- mathgenerator/funcs/algebra/basic_algebra.py | 10 +++++-- mathgenerator/funcs/algebra/log.py | 11 ++++++-- .../algebra/multiply_int_to_22_matrix.py | 28 +++++++++++++++++-- test.py | 14 +--------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/mathgenerator/funcs/algebra/basic_algebra.py b/mathgenerator/funcs/algebra/basic_algebra.py index 0626cf8..2d0a3fb 100644 --- a/mathgenerator/funcs/algebra/basic_algebra.py +++ b/mathgenerator/funcs/algebra/basic_algebra.py @@ -1,7 +1,7 @@ from .__init__ import * -def basicAlgebraFunc(maxVariable=10): +def basicAlgebraFunc(maxVariable=10, style='raw'): a = random.randint(1, maxVariable) b = random.randint(1, maxVariable) c = random.randint(b, maxVariable) @@ -20,8 +20,12 @@ def basicAlgebraFunc(maxVariable=10): elif a == 1 or a == i: x = f"{c - b}" - problem = f"{a}x + {b} = {c}" - solution = x + if style == 'latex': + problem = f"\\({a}x + {b} = {c}\\)" + solution = "\\(" + x + "\\)" + else: + problem = f"{a}x + {b} = {c}" + solution = x return problem, solution diff --git a/mathgenerator/funcs/algebra/log.py b/mathgenerator/funcs/algebra/log.py index bc147f2..8bcc16d 100644 --- a/mathgenerator/funcs/algebra/log.py +++ b/mathgenerator/funcs/algebra/log.py @@ -1,13 +1,18 @@ from .__init__ import * -def logFunc(maxBase=3, maxVal=8): +def logFunc(maxBase=3, maxVal=8, style='raw'): a = random.randint(1, maxVal) b = random.randint(2, maxBase) c = pow(b, a) - problem = "log" + str(b) + "(" + str(c) + ")" - solution = str(a) + if style == 'latex': + problem = "\\(\\log_{" + str(b) + "}" + str(c) + "\\)" + print(problem) + solution = "\\(" + str(a) + "\\)" + else: + problem = "log" + str(b) + "(" + str(c) + ")" + solution = str(a) return problem, solution diff --git a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py index 3d79834..4cc0d5b 100644 --- a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py +++ b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py @@ -1,15 +1,37 @@ from .__init__ import * -def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100): +def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100, style='raw'): a = random.randint(0, maxMatrixVal) b = random.randint(0, maxMatrixVal) c = random.randint(0, maxMatrixVal) d = random.randint(0, maxMatrixVal) 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 diff --git a/test.py b/test.py index 33ca0af..1a538e2 100644 --- a/test.py +++ b/test.py @@ -1,15 +1,3 @@ from mathgenerator import mathgen -# test your generators here - -# print(mathgen.addition()) - -# prints each generator in genList -# list = mathgen.getGenList() -#for item in list: -# print(item[2]) - -# print(mathgen.getGenList()) - -print(mathgen.genById(0, maxSum=20, style='latex')[0]) -print(mathgen.genById(1, style='latex')) +print(mathgen.genById(17, style='latex')) From 5baaa11ad6abe0babf6f995c34b7055ae2df8643 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 19:05:38 -0500 Subject: [PATCH 4/7] lint fixes --- .../algebra/multiply_int_to_22_matrix.py | 20 +++++++++---------- test.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py index 4cc0d5b..5e4ba6b 100644 --- a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py +++ b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py @@ -15,18 +15,18 @@ def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100, style='raw'): d1 = d * constant if style == 'latex': - problem = ("\\(" + str(constant) + "\\cdot" + - "\\begin{bmatrix}" + - str(a) + "&" + str(b) + "\\\\" + - str(c) + "&" + str(d) + - "\end{bmatrix}=" + + 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}" + + solution = ("\\(" + "\\begin{bmatrix}" + "" + str(a1) + "&" + str(b1) + "\\\\" + "" + str(c1) + "&" + str(d1) + "" + "\end{bmatrix}" "\\)" ) else: diff --git a/test.py b/test.py index 1a538e2..3aec112 100644 --- a/test.py +++ b/test.py @@ -1,3 +1,3 @@ from mathgenerator import mathgen -print(mathgen.genById(17, style='latex')) +print(mathgen.genById(17, style='latex')[0]) From 6958cda6e9974d09bd30d35b71118d9efe590b1d Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 19:08:56 -0500 Subject: [PATCH 5/7] more lint fixes --- .../funcs/algebra/multiply_int_to_22_matrix.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py index 5e4ba6b..dab2d94 100644 --- a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py +++ b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py @@ -15,20 +15,8 @@ def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100, style='raw'): 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}" - "\\)" - ) + 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}]]" From 3c4b7feaf3efe6a0984d08fc92bf78b621f5c429 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 19:20:09 -0500 Subject: [PATCH 6/7] even more lint fixes --- mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py | 4 ++-- mathgenerator/funcs/basic_math/addition.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py index dab2d94..8b81d41 100644 --- a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py +++ b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py @@ -15,8 +15,8 @@ def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100, style='raw'): 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}\\)" + 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}]]" diff --git a/mathgenerator/funcs/basic_math/addition.py b/mathgenerator/funcs/basic_math/addition.py index 0cd7f61..bd26e8f 100644 --- a/mathgenerator/funcs/basic_math/addition.py +++ b/mathgenerator/funcs/basic_math/addition.py @@ -10,7 +10,7 @@ def additionFunc(maxSum=99, maxAddend=50, style='raw'): c = a + b if style == 'latex': - problem = "\(" + str(a) + '+' + str(b) + "\)" + problem = "\\(" + str(a) + '+' + str(b) + "\\)" solution = str(c) return problem, solution else: @@ -19,5 +19,4 @@ def additionFunc(maxSum=99, maxAddend=50, style='raw'): return problem, solution - addition = Generator("Addition", 0, "a+b=", "c", additionFunc) From fe410288365efe708aea3908211dc538662cb4c1 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 19:22:56 -0500 Subject: [PATCH 7/7] Added extra line for the linter --- mathgenerator/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mathgenerator/__init__.py b/mathgenerator/__init__.py index 2b69d24..0912991 100644 --- a/mathgenerator/__init__.py +++ b/mathgenerator/__init__.py @@ -40,6 +40,7 @@ class Generator: del kwargs['style'] return self.func(*args, **kwargs) + def getGenList(): correctedList = genList[-1:] + genList[:-1] # Orders list by id