Exercise · Tuples and unpacking · lesson 7 of 8
Exercise: minimum and maximum
Write a function min_max(nums) that returns a tuple (smallest, largest) of the smallest and the largest number in the list nums. Do not use the built-in functions min, max and sorted.
min_max([3, 1, 4])→(1, 4)min_max([-2, -8, 0])→(-8, 0)min_max([7])→(7, 7)
Constraints: the list holds 1 to 5 integers from -1000 to 1000; when there is one number, it is both the smallest and the largest; the result is a tuple, not a list.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.