mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import random
|
|
|
|
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)
|
|
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
|
|
problem = str(a) + "+" + str(b) + "="
|
|
solution = str(c)
|
|
return problem, solution
|
|
|
|
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)
|
|
b = random.randint(max(0, (a-maxDiff)), a)
|
|
c = a-b
|
|
problem = str(a) + "-" + str(b) + "="
|
|
solution = str(c)
|
|
return problem, solution
|
|
|
|
print(subtraction())
|