From dc3e40bafeab646941c8fc312811cff357573281 Mon Sep 17 00:00:00 2001 From: samuele Date: Wed, 14 Oct 2020 17:48:31 +0200 Subject: [PATCH] Added multiplication and division --- mathgenerator/mathgen.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 0829dc7..96e9c47 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -35,9 +35,27 @@ def subtractionFunc(maxMinuend = 99, maxDiff = 99): solution = str(c) return problem, solution +def multiplicationFunc(maxRes = 99, maxMulti = 99): + a = random.randint(0, maxMulti) + b = random.randint(0, min(maxRes, maxMulti)) + c = a*b + problem = str(a) + "*" + str(b) + "=" + solution = str(c) + return problem, solution + +def divisionFunc(maxRes = 99, maxDivid = 99): + a = random.randint(0, maxDivid) + b = random.randint(0, min(maxRes, maxDivid)) + c = a/b + problem = str(a) + "/" + str(b) + "=" + solution = str(c) + return problem, solution # || Class Instances #Format is: # = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>) addition = Generator("Addition", 2, "a+b=", "c", additionFunc) subtraction = Generator("Subtraction", 3, "a-b=", "c", subtractionFunc) +multiplication = Generator("Multiplication", 4, "a*b=", "c", multiplicationFunc) +division = Generator("Division", 5, "a/b=", "c", divisionFunc) +