Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
match-case solution in Clear category for Write Quadratic Equation by juestr
def quadr_equation(data: list[int]) -> str:
def p(n, term, op=''):
match n, term:
case 0, _: return ''
case _, '': return f'{op}{n}'
case 1, _: return f'{op}{term}'
case -1, _: return f'-{term}'
case _: return f'{op}{n}*{term}'
def p_(n, term):
return p(abs(n), term, ' - ' if n < 0 else ' + ')
a, x1, x2, *_ = *data, data[1]
b, c = -a*(x1+x2), a*x1*x2
return ''.join((p(a, 'x**2'), p_(b, 'x'), p_(c, ''), ' = 0'))
Aug. 22, 2022
Comments: