CODING PRACTICE - 20 Sum of List Elements

 Sum of List Elements

Given a list of numbers, write a program to print the sum of the numbers in the list.
Input

The first line of input will contain space-separated integers, denoting the elements of the list.
Output

The output should be a single line containing the sum of the integers in the given list.
Explanation

For example, if the given string is the following.
2 5 10 -15 3

Your code should print the sum of the given list elements. So the output should be 5.
Sample Input 1
2 5 10 -15 3
Sample Output 1
5
Sample Input 2
-50 20 3 88 17 3 11 200 1800
Sample Output 2
2092


code:


n = input()
nl = n.split()
ls=0
for num in nl:
    ls=ls+int(num)
print(ls)

Comments

Popular posts from this blog

CODING ASSIGNMENT 3 Library Management

CODING PRACTICE 11 Music Page

CCBP Static Website Coding Assignment 2 Solution | Yoga Page