## Tuesday, May 25, 2021

Solution Exercise 41: python algorithm which determines the list of integers whose last digit is even and the second is odd #### Exercise 41

Write an algorithm in python that extracts from a list of numbers the sublist of numbers whose last digit is even and the second is odd. Example if: L = [21, 14, 346, 728, 136, 19], the algorithm returns the list: [14, 136]

#### Solution

``````def listEvenOdd (L):
# initialization of the list of numbers including the last even number and the next odd number
lEventOdd = []
for n in L:
# determine the last digit of the number n
last = n%10
second = ((n- last) // 10)% 10
# test if the last digit is even and the scond odd
if last%2 == 0 and second%2 != 0:
lEventOdd.append (n)
return lEventOdd

# Example
L = [21, 14, 346, 728, 136, 19]
print (listEvenOdd (L)) # which displays:  [14, 136]``````

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 