Python Practice › Function Programs › Program 5
Sum of a list
Write a Python function to add up the numbers in a list.
Input
[6, 9, 4, 5, 3]
Output
27
Approach
- Loop and add.
Solution
def total(numbers): result = 0 for n in numbers: result += n return result print(total([6, 9, 4, 5, 3]))Output
27
Learn the concept
New to this topic? Read the lesson, then come back.