Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Write Quadratic Equation by kazuki.h
def quadr_equation(data):
try: a, x1, x2 = data
except ValueError:
a, x1 = data
x2 = x1
b, c = -1 * a * (x1+x2), a * x1 * x2
result = ""
if a == 1: result += "x**2"
elif a == -1: result += "-x**2"
else: result += str(a)+"*x**2"
if b == 1: result += " + x"
elif b == -1: result += " - x"
elif b < 0: result += " - "+str(abs(b))+"*x"
elif b > 0: result += " + "+str(b)+"*x"
if c < 0: result += " - "+str(abs(c))
elif c > 0: result += " + "+str(c)
return result + " = 0"
Aug. 21, 2022
Comments: