mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
31 lines
673 B
Python
31 lines
673 B
Python
from .__init__ import *
|
|
from ..__init__ import Generator
|
|
|
|
|
|
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
|
|
|
|
|
|
basicAlgebra = Generator("Basic Algebra", 11, "ax + b = c", "d",
|
|
basicAlgebraFunc)
|