'int' object is not callable error in python

末鹿安然 提交于 2019-12-19 02:14:13

问题


I'm getting this error:

Traceback (most recent call last):
  File "C:\Users\George\Desktop\ex3.py", line 15, in <module>
    s=s+d*2(-1/6.)*(u-1)*(u-2)*(u+2)*(u-4)
TypeError: 'int' object is not callable

Here is my code:

x=input()
z=input()
n=input()
while x>=z:
    x=input()
    z=input()
while n<0:
    n=input()
while n>0:
    d=(z-x)/1.*n
    k=1
    s=(d/2.)*((-1/6.)*(x-1)*(x-2)*(x+2)*(x-4)+(-1/6.)*(z-1)*(z-2)*(z+2)*(z-4))
    while k<=n-1:
        u=x+k*d
        s=s+d*2(-1/6.)*(u-1)*(u-2)*(u+2)*(u-4)
        k=k+1
        print "%.3f" %s
        x=input()
        z=input()
        n=input()
        if n>0:
            while x>=z:
                x=input()
                z=input()

回答1:


You are trying to use 2 as a function:

2(-1/6.)

Insert a * to multiply:

2*(-1/6.)

or as a full expression:

s=s+d*2*(-1/6.)*(u-1)*(u-2)*(u+2)*(u-4)


来源:https://stackoverflow.com/questions/20151855/int-object-is-not-callable-error-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!