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.
Your code should print the sum of the given list elements. So the output should be 5.
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 1Sample Output 1
2 5 10 -15 3
5
Sample Input 2Sample Output 2
-50 20 3 88 17 3 11 200 1800
2092
code:
n = input()
nl = n.split()
ls=0
for num in nl:
ls=ls+int(num)
print(ls)
Comments
Post a Comment