首页 > 解决方案 > 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

标签: pythonfunctionsum

解决方案


此代码将转换为整数并将它们相加

a=input()
b=a.split(';')
sum=0
for num in b:
     sum+=int(num)
print(sum)

推荐阅读