Improved module format

This commit is contained in:
lukew3
2020-10-19 12:16:03 -04:00
parent f723fb1881
commit 6a0aff7652
5 changed files with 31 additions and 8 deletions

View File

@@ -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

View File

@@ -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 *

View File

@@ -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)

View File

@@ -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)

View File

@@ -3,4 +3,4 @@ from mathgenerator import mathgen
#test your generators here #test your generators here
print(mathgen.addition()) print(mathgen.addition())
print(mathgen.genById(74)) print(mathgen.genById(10))