Просмотрите список коэффициентов и создайте список строк с текстовым представлением каждого термина, затем соедините их с помощью «+», чтобы создать уравнение.
def f(coefficients):
def term(coef, power):
coef = coef if coef != 1 else ''
power = (f'^{power}') if power > 1 else ''
return f'{coef}x{power}'
terms = []
for power, coef in enumerate(coefficients, start=1):
if coef != 0:
terms.append(term(coef, power))
return 'y = ' + ' + '.join(terms)
equation = f([8, 7, 0, -9, 1])
print(equation) # prints 'y = 8x + 7x^2 + -9x^4 + x^5'