Trimmed Average
Sometimes an average is easier to trust after removing one unusually large value and one unusually small value. Write a function centered_average that takes a list nums with at least three numbers. Remove one maximum and one minimum value, calculate the average of the remaining numbers, and return it using integer division.
Примеры
Ввод
[1, 2, 3, 4, 100]Вывод
3Ввод
[1, 1, 5, 5, 10, 8, 7]Вывод
5Ввод
[-10, -4, -2, -4, -2, 0]Вывод
-3Нужно реализовать
def centered_average(nums: list[int]) -> int:
Теги
listsarraymath
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
[1,2,3,4,100]Expected
32
Input
[1,1,5,5,10,8,7]Expected
53
Input
[-10,-4,-2,-4,-2,0]Expected
-34
Input
[5,3,4,6,2]Expected
45
Input
[1,2,3]Expected
26
Input
[0,0,0,0,0]Expected
0Focus radio
Paused · SomaFM · Fluid