Exercise 9
Write an algorithm in python as a function which takes as a parameter a tuple (L, a) formed by a list L and an element 'a' and which returns True if the element 'a' is present in the list L and False if nope.
Solution
|
1 2 3 4 5 6 7 8 9 10 11 12 |
def examinList(L, a): if a in L: return True else: return False # Example L = [13, 9, 17, 23] a = 17 b = 55 print(examinList(L,a)) # The output is: True print(examinList(L,b)) # The output is: False |
Younes Derfoufi
CRMEF OUJDA
Acheter sur Très Facile !
-

Obtenez Microsoft 365 Famille avec Office 365 apps - 15 Mois + NORTON 360 Deluxe - PC/MAC, tablette et smartphone
€ 57,00 Acheter le produit -

Routeur Intelligent Tenda AC6 WiFi sans Fil double Bande AC1200
€ 20,00 Acheter le produit -

Apprendre Raspberry Pi : Série pour les Nuls 2ème édition
€ 24,00 Acheter le livre
1 thought on “Solution Exercise 9: python algorithm that tests if an element is present in a list”