Returning Several Values
~9 mincode completion
Write summarise(numbers) that returns three values in this order: the smallest, the largest, and the mean.
[1, 2, 3, 4] returns (1, 4, 2.5). Assume the list is not empty.
Examples
Smallest, largest and mean of four numbers, in that order
- Input
- summarise([1, 2, 3, 4])
- Output
- [1, 4, 2.5]
A single item is its own min, max and mean
- Input
- summarise([5])
- Output
- [5, 5, 5]
Negative values are handled correctly
- Input
- summarise([-4, 0, 4])
- Output
- [-4, 4, 0]
Hints
Hint 1
Work directly with the arguments numbers and return the result rather than printing it.
Hint 2
Make sure you are not returning values in wrong order.
Requirements
numbers: a non-empty list of numbersReturn a tuple (smallest, largest, mean).
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~9 min
••••••
3 employers weight this skill
2 frontier labs, 1 AI product company. Top match scores 80.
Python
def summarise(numbers):
"""
Describe a list of numbers in three figures.
Args:
numbers: a non-empty list of numbers
Returns:
A tuple (smallest, largest, mean).
"""
# YOUR CODE HERE
pass