我遇到了辛普森規則的問題。跟它浮點對象不能在範圍被解釋爲整數對於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-一個整數) –