Learn Programming and technology with ease @ developerpublish.com

HomePythonPython Program to Find the Cumulative Sum of a List

# Python Program to Find the Cumulative Sum of a List

Pythonâ€™s versatility shines when it comes to solving various programming challenges. In this example, weâ€™ll create a Python program to find the cumulative sum of a given list of numbers.

## Problem Statement

Write a Python program to calculate and display the cumulative sum of a given list. Given an input list, your program should generate an output list where each element represents the cumulative sum of all preceding elements, including itself.

## Python Program to Find the Cumulative Sum of a List

```def cumulative_sum(input_list):
cumulative = []
current_sum = 0

for num in input_list:
current_sum += num
cumulative.append(current_sum)

return cumulative

# Input and Output
input_list = [3, 5, 2, 8, 10]
result = cumulative_sum(input_list)
print("Input List:", input_list)
print("Cumulative Sum List:", result)```

## Input / Output

### You May Also Like

#### Python Program to Remove Duplicates from a Linked List

In this Python program, we will create a singly linked list and remove duplicate elements from it. A linked list...

#### Python Program to Solve the Celebrity Problem

This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...

#### Python Program to Solve n-Queen Problem with Recursion

This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...