diff --git a/README.md b/README.md index d2043a6..966f13b 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,11 @@ problem, solution = mathgen.addition() | Id | Skill | Example problem | Example Solution | Function Name | Status | |------|----------------------------|-----------------|-------------------|--------------------------|-------------| -| 2 | Addition | 1+5= | 6 | addition | Complete | -| 3 | Subtraction | 9-4= | 5 | subtraction | Complete | -| 4 | Multiplication | 4*6= | 24 | multiplication | Complete | -| 5 | Division | 4/2= | 2 | division | Complete | -| 6 | Binary Complement 1s | 1010= | 0101 | binaryComplement1s | Complete | -| 7 | Modulo Division | 10%3= | 1 | moduloDivision | Complete | -| 8 | Square Root | sqrt(a)= | b | squareRootFunction | Complete | -| 9 | Power Rule Differentiation | nx^m | (n*m)x^(m-1) | powerRuleDifferentiation | Complete | +| 0 | Addition | 1+5= | 6 | addition | Complete | +| 1 | Subtraction | 9-4= | 5 | subtraction | Complete | +| 2 | Multiplication | 4*6= | 24 | multiplication | Complete | +| 3 | Division | 4/2= | 2 | division | Complete | +| 4 | Binary Complement 1s | 1010= | 0101 | binaryComplement1s | Complete | +| 5 | Modulo Division | 10%3= | 1 | moduloDivision | Complete | +| 6 | Square Root | sqrt(a)= | b | squareRootFunction | Complete | +| 7 | Power Rule Differentiation | nx^m | (n*m)x^(m-1) | powerRuleDifferentiation | Complete | diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 78b800e..496d9ac 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -1,5 +1,6 @@ import random +genList = [] # || Generator class class Generator: @@ -9,6 +10,7 @@ class Generator: self.generalProb = generalProb self.generalSol = generalSol self.func = func + genList.append(self) def __str__(self): return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol @@ -16,6 +18,10 @@ class Generator: def __call__(self): return self.func() +# || CallbyId +def genById(id): + generator = genList[id] + return(generator()) # || Functions @@ -53,13 +59,13 @@ def divisionFunc(maxRes = 99, maxDivid = 99): def binaryComplement1sFunc(maxDigits = 10): question = '' - answer = '' - for i in range(random.randint(1,maxDigits)): - temp = str(random.randint(0, 1)) + answer = '' + for i in range(random.randint(1,maxDigits)): + temp = str(random.randint(0, 1)) question += temp - answer += "0" if temp == "1" else "1" - - problem = question + answer += "0" if temp == "1" else "1" + + problem = question solution = answer return problem, solution @@ -159,7 +165,7 @@ def divisionToIntFunc(maxA=25, maxB=25): def DecimalToBinary(max_dec=99): a = random.randint(1, max_dec) - b = bin(a).replace("0b", "") + b = bin(a).replace("0b", "") problem = "Binary of "+str(a)+"=" solution = str(b) return problem, solution @@ -201,20 +207,21 @@ def divideFractionsFunc(maxVal=10): #Format is: #