编写一个名为sum_num.py的shell(基于文本)程序,该程序要求用户输入以分号(;)分隔的数字列表,并计算出总数。请参见下面的示例。
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
答案 0 :(得分:0)
此代码将转换为整数并求和
a=input()
b=a.split(';')
sum=0
for num in b:
sum+=int(num)
print(sum)