Exercise 59
Write an algorithm in python which finds the list of all even integers from a given integer m to another given integer n. Example for m = 10 and n 15, the searched list is L = [10, 12, 14]
Solution
def listEven(m , n):
# Initializing the searched list
evenNumbers = []
for i in range(m , n+1):
if i%2 == 0:
evenNumbers.append(i)
return evenNumbers
# Testing algorithm
print(listEven(20 , 31))
# The output is : [20, 22, 24, 26, 28, 30]
Younes Derfoufi
my-courses.net
my-courses.net