Exercise9

Write an algorithm in python as a function which takes as 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 no.

Solution

def examineList (L, a):
if a in L:
return True
else: return False
# Example
L = [13, 9, 5, 23]
a = 5
print (examineList (L, a)) # the output is: True

Younes Derfoufi
my-courses.net

Leave a Reply