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
PostgreSQLv16

Tu sa zobrazí výsledok spustenia kódu

Visible tests
1
Input
[1,2,3,4]
Expected2.5
2
Input
[10]
Expected10
3
Input
[]
Expected0
4
Input
[2,4,6]
Expected4
5
Input
[1,2,3,4,5,6,7,8,9,10]
Expected5.5
6
Input
[-1,1]
Expected0
Focus radio
Paused · SomaFM · Fluid