Files
mathgenerator/mathgenerator/funcs/algebra/basic_algebra.py
2020-11-20 20:17:28 -05:00

30 lines
642 B
Python

from .__init__ import *
def basicAlgebraFunc(maxVariable=10):
a = random.randint(1, maxVariable)
b = random.randint(1, maxVariable)
c = random.randint(b, maxVariable)
# calculate gcd
def calculate_gcd(x, y):
while (y):
x, y = y, x % y
return x
i = calculate_gcd((c - b), a)
x = f"{(c - b)//i}/{a//i}"
if (c - b == 0):
x = "0"
elif a == 1 or a == i:
x = f"{c - b}"
problem = f"{a}x + {b} = {c}"
solution = x
return problem, solution
basic_algebra = Generator("Basic Algebra", 11, "ax + b = c", "d",
basicAlgebraFunc)