Exercise 20

Write a Python algorithm which returns the maximum of the list without using any predefined function in Python.


def maximumList (L):
# initialization of the list maximum
maxList = L [0]
for x in L:
if maxList < x:
maxList = x

return maxList
L = [15, 31, 12, 7, 19, 23, 29]

print ("The maximum of list L is:", maximumList (L))
# The output is: the maximum of the list L is: 31

Younes Derfoufi

Leave a Reply