diff --git a/mathgenerator/__init__.py b/mathgenerator/__init__.py index e69de29..9a5f3ea 100644 --- a/mathgenerator/__init__.py +++ b/mathgenerator/__init__.py @@ -0,0 +1,20 @@ + +genList = [] + +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 + genList.append([id, title, self]) + + def __str__(self): + return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol + + def __call__(self, **kwargs): + return self.func(**kwargs) + +def getGenList(): + return genList diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index 4bfd99e..0cca17b 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -2,7 +2,7 @@ import random import math import fractions -from .additionFunc import * +from .addition import * from .subtractionFunc import * from .multiplicationFunc import * from .divisionFunc import * diff --git a/mathgenerator/funcs/additionFunc.py b/mathgenerator/funcs/addition.py similarity index 80% rename from mathgenerator/funcs/additionFunc.py rename to mathgenerator/funcs/addition.py index 30dfefe..b1cc1d6 100644 --- a/mathgenerator/funcs/additionFunc.py +++ b/mathgenerator/funcs/addition.py @@ -1,5 +1,5 @@ from .__init__ import * - +from ..__init__ import Generator def additionFunc(maxSum=99, maxAddend=50): a = random.randint(0, maxAddend) @@ -8,3 +8,5 @@ def additionFunc(maxSum=99, maxAddend=50): problem = str(a) + "+" + str(b) + "=" solution = str(c) return problem, solution + +addition = Generator("Addition", 0, "a+b=", "c", additionFunc) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 89bf086..064c69a 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -2,8 +2,9 @@ import random import math import fractions from .funcs import * +from .__init__ import getGenList -genList = [] +genList = getGenList() # || Generator class class Generator: @@ -28,13 +29,13 @@ def genById(id): return(generator()) # -def getGenList(): - return(genList) +#def getGenList(): +# return(genList) # Format is: #