Exercise 31
Write a Python program that retrieves the list of even integers and the list of odd integers from a list of numbers.
Solution
# 1) define the function that retrieves the list of enven integers
def evenIntegers(l):
# define the list of even integer
even = []
# Browse the evens integers in the list l
for n in l:
if(n%2 == 0):
even.append(n)
return even
# 1) define the function that retrieves the list of odd integers
def oddIntegers(l):
# define the list of even integer
odd = []
# Browse the odd integers in the list l
for n in l:
if(n%2 != 0):
odd.append(n)
return odd
# Example
l = [4 , 3 , 5 , 18 , 13 , 23 , 48]
print("The list of evens integers is : ", evenIntegers(l))
print("The list of odd integers is : ", oddIntegers(l))
Younes Derfoufi