mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
1.0.1 formatting fixes
This commit is contained in:
0
mathgenerator/__init__.py
Normal file
0
mathgenerator/__init__.py
Normal file
43
mathgenerator/mathgen.py
Normal file
43
mathgenerator/mathgen.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import random
|
||||
|
||||
# || Generator class
|
||||
|
||||
class Generator:
|
||||
def __init__(self, title, id, generalProb, generalSol, func):
|
||||
self.title = title
|
||||
self.id = id
|
||||
self.generalProb = generalProb
|
||||
self.generalSol = generalSol
|
||||
self.func = func
|
||||
|
||||
def __str__(self):
|
||||
return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol
|
||||
|
||||
def __call__(self):
|
||||
return self.func()
|
||||
|
||||
|
||||
# || Functions
|
||||
|
||||
def additionFunc(maxSum = 99, maxAddend = 50):
|
||||
a = random.randint(0, maxAddend)
|
||||
b = random.randint(0, min((maxSum-a), 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
|
||||
c = a+b
|
||||
problem = str(a) + "+" + str(b) + "="
|
||||
solution = str(c)
|
||||
return problem, solution
|
||||
|
||||
def subtraction(maxMinuend = 99, maxDiff = 99):
|
||||
a = random.randint(0, maxMinuend)
|
||||
b = random.randint(max(0, (a-maxDiff)), a)
|
||||
c = a-b
|
||||
problem = str(a) + "-" + str(b) + "="
|
||||
solution = str(c)
|
||||
return problem, solution
|
||||
|
||||
# || Class Instances
|
||||
|
||||
#Format is:
|
||||
#<title> = 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)
|
||||
Reference in New Issue
Block a user