Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a function min_max(numbers) that returns the smallest and the biggest number. What does it give for [4, 9, 2, 7]?
return a, b sends back a tuple of two values.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. return min(numbers), max(numbers) sends two values back, as a tuple.
For [4, 9, 2, 7] the result is (2, 9). The caller can unpack it: low, high = min_max(...).
Log in to join the discussion.
Loading…