features-Python-courses-python-exercises-python-oop

Exercise 19

Write an algorithm in python as a function which takes as parameter a list of numbers L and which returns the minimum of the list without using any predefined function in Python.

Solution

def minimumList (L):
# initializing the minimum of the list
minList = L [0]
for x in L:
if minList> x:
minList = x

return minList
#Example
L = [15, 31, 12, 7, 19, 23, 29]

print ("The minimum of list L is:", minimumList (L))
# The output is: The minimum of the list L is: 7

Younes Derfoufi
my-courses.net

Leave a Reply