Python-courses-python-exercises-python-students-online-courses

Exercise 20

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

Solution

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

return maxList
#Example
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
my-courses.net

Leave a Reply