From eb4160b6660c6f251aa9f3cd47888be73349cbce Mon Sep 17 00:00:00 2001 From: Ganesh Futane <63470761+ganesh003@users.noreply.github.com> Date: Wed, 14 Oct 2020 16:37:29 -0700 Subject: [PATCH] Update mathgen.py --- mathgenerator/mathgen.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 87f6d56..a099fd5 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -92,6 +92,14 @@ def powerRuleDifferentiationFunc(maxCoef = 10, maxExp = 10, maxTerms = 5): solution += str(coefficient * exponent) + "x^" + str(exponent - 1) return problem, solution +def squareFunc(maxSquareNum = 20): + a = random.randint(1, maxSquareNum) + b = a * a + problem = str(a) + "^2" + "=" + solution = str(b) + return problem, solution + + # || Class Instances #Format is: @@ -104,3 +112,4 @@ binaryComplement1s = Generator("binary_complement_1s", 6, "1010=", "0101", binar moduloDivision = Generator("Modulo_Division", 7, "a%b=", "c", moduloFunc) squareRoot = Generator("Square_Root", 8, "sqrt(a)=", "b", squareRootFunction) powerRuleDifferentiation = Generator("Power_Rule_Differentiation", 9, "nx^m=", "(n*m)x^(m-1)", powerRuleDifferentiationFunc) +square = Generator("Square", 10,"a^2", "b", squareFunc)