mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
Improved module format
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import random
|
|||||||
import math
|
import math
|
||||||
import fractions
|
import fractions
|
||||||
|
|
||||||
from .additionFunc import *
|
from .addition import *
|
||||||
from .subtractionFunc import *
|
from .subtractionFunc import *
|
||||||
from .multiplicationFunc import *
|
from .multiplicationFunc import *
|
||||||
from .divisionFunc import *
|
from .divisionFunc import *
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from .__init__ import *
|
from .__init__ import *
|
||||||
|
from ..__init__ import Generator
|
||||||
|
|
||||||
def additionFunc(maxSum=99, maxAddend=50):
|
def additionFunc(maxSum=99, maxAddend=50):
|
||||||
a = random.randint(0, maxAddend)
|
a = random.randint(0, maxAddend)
|
||||||
@@ -8,3 +8,5 @@ def additionFunc(maxSum=99, maxAddend=50):
|
|||||||
problem = str(a) + "+" + str(b) + "="
|
problem = str(a) + "+" + str(b) + "="
|
||||||
solution = str(c)
|
solution = str(c)
|
||||||
return problem, solution
|
return problem, solution
|
||||||
|
|
||||||
|
addition = Generator("Addition", 0, "a+b=", "c", additionFunc)
|
||||||
@@ -2,8 +2,9 @@ import random
|
|||||||
import math
|
import math
|
||||||
import fractions
|
import fractions
|
||||||
from .funcs import *
|
from .funcs import *
|
||||||
|
from .__init__ import getGenList
|
||||||
|
|
||||||
genList = []
|
genList = getGenList()
|
||||||
|
|
||||||
# || Generator class
|
# || Generator class
|
||||||
class Generator:
|
class Generator:
|
||||||
@@ -28,13 +29,13 @@ def genById(id):
|
|||||||
return(generator())
|
return(generator())
|
||||||
|
|
||||||
#
|
#
|
||||||
def getGenList():
|
#def getGenList():
|
||||||
return(genList)
|
# return(genList)
|
||||||
|
|
||||||
# Format is:
|
# Format is:
|
||||||
# <title> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>)
|
# <title> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>)
|
||||||
# Funcs_start - DO NOT REMOVE!
|
# Funcs_start - DO NOT REMOVE!
|
||||||
addition = Generator("Addition", 0, "a+b=", "c", additionFunc)
|
#addition = Generator("Addition", 0, "a+b=", "c", additionFunc)
|
||||||
subtraction = Generator("Subtraction", 1, "a-b=", "c", subtractionFunc)
|
subtraction = Generator("Subtraction", 1, "a-b=", "c", subtractionFunc)
|
||||||
multiplication = Generator("Multiplication", 2, "a*b=", "c", multiplicationFunc)
|
multiplication = Generator("Multiplication", 2, "a*b=", "c", multiplicationFunc)
|
||||||
division = Generator("Division", 3, "a/b=", "c", divisionFunc)
|
division = Generator("Division", 3, "a/b=", "c", divisionFunc)
|
||||||
|
|||||||
Reference in New Issue
Block a user