## Friday, April 16, 2021

Solution Exercise 11: Multiply the elements of a Python list by a given integer

#### Exercise 11

Write an algorithm in python as a function which takes as parameter a tuple (L, n) formed by a list L of numbers and an integer n and which returns the list obtained from L by multiplying its elements by n . Example if L = [3, 9, 5, 23] and n = 2 the function returns the list: [6, 18, 10, 46]

#### Solution

``````def listMultiply (L, n):
# initialization of the searched list
l_mult = []
# iterate over and multiply the elements of the list by n
for x in L:
l_mult.append (n * x)

return l_mult

# Example
n = 2
L = [3, 9, 5, 23]
print (listMultiply (L, n)) # the out put is :  [6, 18, 10, 46]``````

Younes Derfoufi
my-courses.net

#### 1 comment:

1. n=int(input())
l=[3,9,5,23]
for i in l:
m=i*n
print(m,end=" ")

## 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 