## Saturday, May 22, 2021

Solution Exercise 37: python algorithm which determines the list of numbers containing the digit 3 #### Exercise 37

Write a python algorithm that extracts from a given list of numbers the sublist made up of numbers that contain the digit 3.

#### Solution

``````# method which tests whether or not a number contains the digit 3
def contains3 (n):
# convert n to string
s = str (n)
if '3' in s:
return True
else:
return False

# method that determines the list of numbers that contain the digit 3

def listContains3 (L):
# initialization of the list of numbers that contain the digit 3
list3 = []
for n in L:
if contains3 (n):
list3.append (n)
return list3

# Example
L = [21, 137, 25, 31, 71, 239]
print (listContains3 (L)) # print [137, 31, 239]``````

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 