## Monday, September 13, 2021

Solution Exercise 90 *: python algorithm which transforms a list by adding its terms

#### Exercise 90 *

Given a list of integers
``L = [n1, n2, n3, ..., np]``
, write an algorithm in python which returns the list:
``L_sum = [n1, n1 + n2, n1 + n2 + n3, .. ., n1 + n2 + n3 + ... + np]``

#### Solution

``````# function which calculates the sum of the list elements
def sumList (L):
# initialization of the sum of the list elements
s = 0
for x in L:
s = s + x
return s

# function which determines the list L_sum
def sum_list (L):
# initializationh of the list L_sum
L_sum = []
for i in range (0, len (L)):
L_sum.append (sumList (L [0: i+1]))

return L_sum

# Example
L = [3, 2, 5, 1, 0, 7]
print ("L_sum =", sum_list (L))``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 