easy +7 pts

Average excluding min and max

Compute the mean of a list after removing the smallest and largest values.

Write a function `average_excluding_min_max(numbers)` that takes a list of integers (length at least 3) and returns the arithmetic mean (as a float) of the list after removing one occurrence of the smallest value and one occurrence of the largest value. The original list must not be modified. Examples: - `average_excluding_min_max([1, 2, 3, 4, 5])` returns `3.0` (remove 1 and 5, average of 2,3,4). - `average_excluding_min_max([10, 5, 20, 15])` returns `12.5` (remove 5 and 20, average of 10 and 15). If the list has exactly three elements and all three are equal, after removing one min and one max there is only one element left; the average is that element (e.g., `[7,7,7]` -> `7.0`).

Constraints

- The input list always contains at least 3 integers (3 ≤ len(numbers) ≤ 1000). - Each integer may be as large as ±10^9. - The function should return a float; do not perform integer division. - Original list must remain unchanged.

Example

>>> average_excluding_min_max([1, 2, 3, 4, 5])
3.0
>>> average_excluding_min_max([10, 5, 20, 15])
12.5
>>> average_excluding_min_max([7, 7, 7])
7.0
7 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use the `min()` and `max()` built-ins to find the extremes.
Remove only one occurrence of each extreme. You can use `list.remove()` or find an index.
After removal, use `sum()` and `len()` to compute the average.
Consider what remains when all elements are equal.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.