created genById function

This commit is contained in:
lukew3
2020-10-15 10:10:16 -04:00
parent 977c5e06e1
commit 61490c3fce

View File

@@ -1,5 +1,6 @@
import random import random
genList = []
# || Generator class # || Generator class
class Generator: class Generator:
@@ -9,6 +10,7 @@ class Generator:
self.generalProb = generalProb self.generalProb = generalProb
self.generalSol = generalSol self.generalSol = generalSol
self.func = func self.func = func
genList.append(self)
def __str__(self): def __str__(self):
return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol
@@ -16,6 +18,10 @@ class Generator:
def __call__(self): def __call__(self):
return self.func() return self.func()
# || CallbyId
def genById(id):
generator = genList[id-2]
return(generator())
# || Functions # || Functions
@@ -53,13 +59,13 @@ def divisionFunc(maxRes = 99, maxDivid = 99):
def binaryComplement1sFunc(maxDigits = 10): def binaryComplement1sFunc(maxDigits = 10):
question = '' question = ''
answer = '' answer = ''
for i in range(random.randint(1,maxDigits)): for i in range(random.randint(1,maxDigits)):
temp = str(random.randint(0, 1)) temp = str(random.randint(0, 1))
question += temp question += temp
answer += "0" if temp == "1" else "1" answer += "0" if temp == "1" else "1"
problem = question problem = question
solution = answer solution = answer
return problem, solution return problem, solution
@@ -159,7 +165,7 @@ def divisionToIntFunc(maxA=25, maxB=25):
def decimalToBinary(max_dec=99): def decimalToBinary(max_dec=99):
a = random.randint(1, max_dec) a = random.randint(1, max_dec)
b = bin(a).replace("0b", "") b = bin(a).replace("0b", "")
problem = "Binary of "+str(a)+"=" problem = "Binary of "+str(a)+"="
solution = str(b) solution = str(b)
return problem, solution return problem, solution