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