Sum of List Elements

Calculate the sum of all elements in a list of numbers.

PythonBeginner
Python
# Program to find sum of list elements

numbers = list(map(float, input("Enter numbers separated by space: ").split()))

print("Sum of elements:", sum(numbers))

Output

Enter numbers separated by space: 1 2 3 4
Sum of elements: 10.0

We read space-separated numbers, convert them to float, and use the built-in sum() to add them.