我遇到了辛普森规则的问题。跟它浮点对象不能在范围被解释为整数对于i(1,(N/2)+ 1):Python辛普森规则浮点对象错误
def simpson(f, a, b, n):
h=(b-a)/n
k=0.0
x= a + h
for i in range(1, (n/2) + 1):
k += 4*f(x)
x += 2*h
x = a + 2*h
for i in range(1, n/2):
k +=2*f(x)
x += 2*h
return (h/3)*(f(a)+f(b)+k)
结果=辛普森(拉姆达X:X,0,1,4) print(result)
[Python TypeError:'float'object can not be interpret as a integer](http://stackoverflow.com/questions/33355608/python-typeerror-float-object-cannot-be-interpreted-as-一个整数) –