Estou tentando resolver o seguinte exercício:
Problem #1 Implement the evaluate_poly function. This function evaluates a polynomial function for the given x value. It takes in a tuple of numbers poly and a number x. By number, we mean that x and each element of poly is a float. evaluate_poly takes the polynomial represented by poly and computes its value at x. It returns this value as a float.
def evaluate_poly(poly, x):
total = 0.0
for i in xrange(len(poly)):
total += poly[i] * (x ** i)
return total
poly = tuple(float(x.strip()) for x in raw_input('Entre com os coeficientes: ').split(','))
x = raw_input('Entre com valor de x: ')
print evaluate_poly(poly, x)
Estou recebendo os seguintes erros:
Traceback (most recent call last):
line 8, in <module>
print evaluate_poly('poly', 'x')
line 4, in evaluate_poly
total += poly[i] * (x ** i)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Porque estou recebendo tais erros? Também não estou entendendo muito bem a sintaxe de input do tuple, o que é x.strip e .split?