mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Changed to class-based generators
This commit is contained in:
@@ -5,7 +5,17 @@ This project was created with contributions at it's core. We need your help to e
|
|||||||
## How You Can Help
|
## How You Can Help
|
||||||
|
|
||||||
### Coding Generators
|
### Coding Generators
|
||||||
As of right now, all of our generators are being coded in python. Each generator should be contained in a function. Your function should look something like the following:
|
As of right now, all of our generators are being coded in python. Your generator will be an object of the Generator class and will have a function created seperately.
|
||||||
|
Your object instantiation should follow this format:
|
||||||
|
```
|
||||||
|
#g<id> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>)
|
||||||
|
|
||||||
|
```
|
||||||
|
and look something like this:
|
||||||
|
```
|
||||||
|
g2 = Generator("Addition", 2, "a+b=", "c", addition)
|
||||||
|
```
|
||||||
|
Your function should look something like the following:
|
||||||
```
|
```
|
||||||
def addition(maxSum, maxAddend):
|
def addition(maxSum, maxAddend):
|
||||||
"""
|
"""
|
||||||
@@ -25,6 +35,7 @@ def addition(maxSum, maxAddend):
|
|||||||
solution = str(c)
|
solution = str(c)
|
||||||
return problem, solution
|
return problem, solution
|
||||||
```
|
```
|
||||||
|
|
||||||
Before coding, please check README.md to see if someone has already created the generator you plan to make.
|
Before coding, please check README.md to see if someone has already created the generator you plan to make.
|
||||||
Skillid is determined by the next available id as can be determined in the table.
|
Skillid is determined by the next available id as can be determined in the table.
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
# || Generator class
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
return self.func()
|
||||||
|
|
||||||
|
|
||||||
|
# || Functions
|
||||||
|
|
||||||
def addition(maxSum = 99, maxAddend = 50):
|
def addition(maxSum = 99, maxAddend = 50):
|
||||||
"""
|
|
||||||
DESCRIPTION:
|
|
||||||
Generates addition problems with positive addends less than maxAddend and sum less than maxSum
|
|
||||||
SKILLID:
|
|
||||||
2
|
|
||||||
PROBLEM:
|
|
||||||
"a+b="
|
|
||||||
SOLUTION:
|
|
||||||
"c"
|
|
||||||
"""
|
|
||||||
a = random.randint(0, maxAddend)
|
a = random.randint(0, maxAddend)
|
||||||
b = random.randint(0, min((maxSum-a), maxAddend)) #The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
|
b = random.randint(0, min((maxSum-a), maxAddend)) #The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
|
||||||
c = a+b
|
c = a+b
|
||||||
@@ -19,16 +28,6 @@ def addition(maxSum = 99, maxAddend = 50):
|
|||||||
return problem, solution
|
return problem, solution
|
||||||
|
|
||||||
def subtraction(maxMinuend = 99, maxDiff = 99):
|
def subtraction(maxMinuend = 99, maxDiff = 99):
|
||||||
"""
|
|
||||||
DESCRIPTION:
|
|
||||||
Generates subtraction problems with difference between 0 and maxDiff. Minuend and subtrahend are between 0 and maxMinuend.
|
|
||||||
SKILLID:
|
|
||||||
3
|
|
||||||
PROBLEM:
|
|
||||||
"a-b="
|
|
||||||
SOLUTION:
|
|
||||||
"c"
|
|
||||||
"""
|
|
||||||
a = random.randint(0, maxMinuend)
|
a = random.randint(0, maxMinuend)
|
||||||
b = random.randint(max(0, (a-maxDiff)), a)
|
b = random.randint(max(0, (a-maxDiff)), a)
|
||||||
c = a-b
|
c = a-b
|
||||||
@@ -36,4 +35,14 @@ def subtraction(maxMinuend = 99, maxDiff = 99):
|
|||||||
solution = str(c)
|
solution = str(c)
|
||||||
return problem, solution
|
return problem, solution
|
||||||
|
|
||||||
print(subtraction())
|
# || Class Instances
|
||||||
|
|
||||||
|
#Format is:
|
||||||
|
#g<id> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>)
|
||||||
|
g2 = Generator("Addition", 2, "a+b=", "c", addition)
|
||||||
|
g3 = Generator("Subtraction", 3, "a-b=", "c", subtraction)
|
||||||
|
|
||||||
|
# || Testing Zone
|
||||||
|
print(g2)
|
||||||
|
print(g2())
|
||||||
|
print(g3())
|
||||||
|
|||||||
Reference in New Issue
Block a user