如果我使用以下代码手动引入参数,它可以工作:
def evaluatePoly(poly, x):
result = 0
for i in range(len(poly)):
result += poly[i] * x ** i
return float(result)
>>> evaluatePoly([1,2,2],2)
13
我想被要求只介绍系数,不带括号,以及我想评估我的多项式方程的值。像这样的东西:
poly=(raw_input('Enter a list of coefficients from your polynomial equation: '))
x=int(raw_input('Enter the value where you want to evaluate your polynomial equation: '))
print(evaluatePoly(poly, x))
但如果我尝试这样做,Python 会给我这个错误:
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
我该怎么做?
谢谢