在列表中使用 sum()

问题描述

我对编码有点陌生,我有一个学校项目,我们必须使用 python 编写代码,在代码中,我们从用户那里获得输入并需要将其添加到列表中,这是代码:

x = input("Enter the expenses: ")
y = x.split()
n = sum(y)
print("Total: $"+ n +"")

我浏览了整个互联网,显然这是正确的,但出于某种原因,我总是收到一条错误消息:

Traceback (most recent call last):
  File "program.py",line 3,in <module>
    n = sum(y)
TypeError: unsupported operand type(s) for +: 'int' and 'str'

我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)