Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python 3 TypeError:“int”对象不可调用_Python_Python 3.x_Python 2.7 - Fatal编程技术网

python 3 TypeError:“int”对象不可调用

python 3 TypeError:“int”对象不可调用,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,你能告诉我这个代码有什么问题吗 a=int(input()) for i in range(a): lst=list(map(int,input().split(" "))) ans=lst[1] for j in range(lst[0]): ans=(ans(ans+1))/2 print(ans) 它在输出中显示- line 6, in <module> TypeError: 'int' object is not call

你能告诉我这个代码有什么问题吗

 a=int(input())
 for i in range(a):
    lst=list(map(int,input().split(" ")))
    ans=lst[1]
    for j in range(lst[0]):
        ans=(ans(ans+1))/2
    print(ans)
它在输出中显示-

line 6, in <module>
TypeError: 'int' object is not callable

考虑到你试图将它们相乘,这应该是一条线。编写ans会让解释器认为ans是一个函数,而实际上它是一个int

ans = (ans * (ans+1))/2

ans是一个int,但您调用它就像调用一个函数:ansans+1。也许你想在这里繁殖:ans*ans+1谢谢你@schwobasegl。也谢谢你@fred