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 !
-

Hub USB 3.0 OBERSTER Multiport
€ 7,00 Acheter le produit -
Promo !

Routeur WiFi AX 3000 Mbps TP-Link Routeur, WiFi 6, 4 antennes à haute performance, OneMesh, WPA3
Le prix initial était : € 99,00.€ 56,00Le prix actuel est : € 56,00. Acheter le produit -

POO: Cours et exercices en UML2, Python, PHP, C#, C++ et Java (French Edition)
€ 17,00 Achetez le livre
1 thought on “Solution Exercise 9: python algorithm that tests if an element is present in a list”