【发布时间】:2017-06-09 09:00:46
【问题描述】:
我是 python 编程的新手,我想知道如何编写一个 python 程序来获取一些用户输入的整数作为列表并将所有项目添加到其中。这是我编写的代码..
A=list(input("Enter the values of the list "))
total=0
for a in A:
total=total+a
print(total)
当我运行这个程序时,它会说,
Traceback (most recent call last):
File "C:/Users/Jayaweera/Desktop/Python programming/51E5-sum all the items in a list.py", line 4, in <module>
total=total+a
TypeError: unsupported operand type(s) for +: 'int' and 'str'
【问题讨论】:
-
我想要一匹小马……
-
好主意 OP。你为什么不这样做呢?
-
试了好几次都没有得到正确答案