【发布时间】:2020-01-29 02:46:56
【问题描述】:
我试图在单行中查找列表中元素的总和,其中元素取自用户。但是当我运行它显示的程序时,int 对象不可调用。
我的代码:
l=input().split()
print(l)
s=sum(l)
n=len(l)
if(s%n!=0):
print(-1)
当我运行我的程序时:
*error in line3*
TypeError: unsupported operand type(s) for +: 'int' and 'str'
和
'int' object is not callable
【问题讨论】:
-
嗨,这是完整的代码吗?如果不能,您可以发布带有导致错误的行的代码吗?
-
它是否显示 int 不可调用或不受支持的操作数类型?给minimal reproducible example。请注意,
input().split()会给你一个字符串列表。 -
请出示您的
listprint(l)。 -
使用 l = [ int(x) for x in input().split()]
-
不工作@rajenderkumar
标签: python python-3.5