Exercise 201
Write a python program as a function that determines the minimum and maximum values of given a set withowt using any predefined function. Example if
E = {13 , 2 , 47 , 23 , 71 , 17}
, the function returns (2,71)
Solution
def minMax(E):
# converting the set to a list
L = list(E)
# initialising the maximum and minimum
M = L[0]
m = L[0]
for x in L:
if x < m :
m = x
for x in L:
if M < x:
M = x
return (m , M)
# Testing algorithm
E = E = {13 , 2 , 47 , 23 , 71 , 17}
print("(minimum , maximum) = " , minMax(E))
# The output is : (minimum , maximum) = (2, 71)
Younes Derfoufi
my-courses.net
my-courses.net