Updated Basic Algebra Function

fixed the denominator issue
This commit is contained in:
Ganesh Futane
2020-10-14 17:10:40 -07:00
committed by GitHub
parent d61bb0ec83
commit d3468fe926

View File

@@ -121,6 +121,26 @@ def lcmFunc(maxVal=20):
solution = str(d)
return problem, solution
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
# || Class Instances
#Format is:
@@ -136,3 +156,4 @@ powerRuleDifferentiation = Generator("Power_Rule_Differentiation", 9, "nx^m=", "
square = Generator("Square", 10,"a^2", "b", squareFunc)
lcm = Generator("Lcm_generator", 11, "LCM of a and b = ", "c", lcmFunc)
gcd = Generator("Gcd_generator", 12, "GCD of a and b = ", "c", gcdFunc)
basicAlgebra = Generator("Basic_Algebra", 13, "ax + b = c", "d", basicAlgebraFunc)