Saturday 16 May 2015

Python program to calculate the sum of elements in a list


This is a Python program which calculates the sum of all the elements in a list.

Here we use a function called sum() to calculate the sum of all the items in a list.




PROGRAM : 
lst = []
num = int(input('How many numbers: '))
for n in range(num):
    numbers = int(input('Enter number '))
    lst.append(numbers)
print("Sum of elements in given list is :", sum(lst))


OUTPUT : 
Python  - Sum of all items in a list



Similar Programs : 
C program to calculate the sum of elements in a array
Cpp program to calculate the sum of elements in a array
Java program to calculate the sum of elements in a array