• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
22 views

Problem:

I have a problem in which , we are passing in an list of numbers. add up all the list elements and output the result. I am quiet new in python , can anyone give me program code to tackle this?

The list of numbers might be for example [1,2,3,4,5] .

by (550 points)  

1 Answer

0 votes

Solution:

Following program will give the right solution

list_of_no = str(input("Enter list of no in such order[1,2,3,4,5]:\t"))
totNo = 0
list_of_no = list_of_no.split() 
for value in list_of_no:
    try:
        value = int(value) 
    except:
        continue
    totNo += value

print(totNo)

by (5.3k points)  
...