python - i cant sum the numbers (python)
问题描述
Write a shell (text-based) program, called sum_num.py, that asks the user for a semicolon (;) separated list of numbers, and calculated the total. See the example below.
a = str(raw_input("Enter semicolon separated list of integers:"))
b = a.split(";")
c = (a[0:])
print("the total is " + sum(c))
PS C:\Users\ssiva\Desktop> python sum_num.py
Enter semicolon separated list of integers: 3;10;4;23;211;3
The total is 254
解决方案
此代码将转换为整数并将它们相加
a=input()
b=a.split(';')
sum=0
for num in b:
sum+=int(num)
print(sum)
推荐阅读
- django - django context_processors,请求'function'对象没有属性'path'
- c# - c# 多部分表单数据编码
- excel - 这个excel VBA范围定义有什么错误?
- html - 在圆周上绝对定位元素
- javascript - 具有相同值的“顶部”属性显示不同
- reactjs - 错误:操作必须是普通对象。使用自定义中间件进行异步操作。但我没有异步功能
- javascript - 单击以打开 PDF - 您可能需要适当的加载程序来处理此文件类型
- mysql - 优化大型 MySQL 表中的索引
- javascript - 未捕获的类型错误:无法读取未定义的属性“addPoint”(Highstock 实时数据)
- javascript - 如何使用 Listners 打印参数而不是值。当我的字符串返回 null 作为每个输出的前缀时,还有什么问题?