Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
sympy expand solution in Creative category for Write Quadratic Equation by Sim0000
from sympy import *
def quadr_equation(data: list[int]) -> str:
a, x1, x2 = data if len(data) == 3 else (*data, data[1])
var('x')
return str(expand(a * (x - x1) * (x - x2), x)) + ' = 0'
print("Example:")
print(quadr_equation([2, 4, 6]))
assert quadr_equation([2, 4, 6]) == "2*x**2 - 20*x + 48 = 0"
assert quadr_equation([-2, 4, 6]) == "-2*x**2 + 20*x - 48 = 0"
assert quadr_equation([2, 4, -4]) == "2*x**2 - 32 = 0"
assert quadr_equation([2, 4, 0]) == "2*x**2 - 8*x = 0"
assert quadr_equation([2, 0]) == "2*x**2 = 0"
assert quadr_equation([2, 4]) == "2*x**2 - 16*x + 32 = 0"
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 21, 2022
Comments: