Unpacking a Multi-Value Return

Easy ⏱ 8 min 73% acceptance ★★★★★ 4.7
Write a function min_max_avg(numbers) that returns a tuple (minimum, maximum, average) for a non-empty list of numbers, where average is a float. Demonstrate that a caller can unpack this into three separate variables in one line.

Examples

Example 1
Input
min_max_avg([4, 8, 2, 10])
Output
(2, 10, 6.0)
Explanation

min=2, max=10, avg=(4+8+2+10)/4=6.0.

Example 2
Input
min_max_avg([5])
Output
(5, 5, 5.0)
Explanation

Single-element list: all three stats equal 5.

Constraints

  • numbers is a non-empty list of ints or floats.

Topics

Variables & Data Typestuple unpacking

Companies

OracleIBM

Hints

Hint 1

Use built-in min(), max() and sum()/len().

Hint 2

Return the three values as a tuple literal, e.g. `(lo, hi, avg)`.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.