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 !
-
Python pour Excel: Automatisation et Analyse des Données
€ 34,00 Acheter le livre -
Disque dur EMTEC SSD Interne X150 240 Go- Prix Abordable
€ 21,00 Acheter le produit -
Répéteur WiFi,1200Mbps Dual Band 2.4G / 5G WiFi Amplifier,WiFi Signal Booster,2 Ports LAN ,4 Antennes,WiFi Extenders
€ 18,00 Acheter le produit
1 thought on “Solution Exercise 9: python algorithm that tests if an element is present in a list”