Average Value
The arithmetic mean helps you quickly understand a typical value in a list, such as an average score, price, or time. Write a function mean that adds all numbers in nums and divides the sum by the number of items. If the list is empty, return 0 to avoid division by zero. Use ordinary division, so the result may be fractional.
Примеры
Ввод
[1, 2, 3, 4]Вывод
2.5Ввод
[10]Вывод
10Ввод
[]Вывод
0Нужно реализовать
def mean(nums: list[float]) -> float:
Теги
matharraylists
Zaloguj się, aby zobaczyć historię rozwiązań
Zaloguj sięZaloguj się, aby korzystać z Mentora AI
Zaloguj sięVisible tests
1
Input
[1,2,3,4]Expected
2.52
Input
[10]Expected
103
Input
[]Expected
04
Input
[2,4,6]Expected
45
Input
[1,2,3,4,5,6,7,8,9,10]Expected
5.56
Input
[-1,1]Expected
0Focus radio
Paused · SomaFM · Fluid