반응형
Description:
Write a function which calculates the average of the numbers in a given list.
Note: Empty arrays should return 0.
Solution:
1. If 'numbers' is an empty array, 0 is returned.
2. If it is not empty, the average value is returned.
import statistics
def find_average(numbers):
return statistics.mean(numbers) if numbers else 0
statistics.mean() is a Python built-in library that calculates the average value of an array.
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Transportation on vacation (0) | 2022.04.08 |
---|---|
Beginner - Lost Without a Map (0) | 2022.04.07 |
Hide Kata Description (0) | 2022.04.05 |
How Green Is My Valley? (0) | 2022.04.04 |
Regexp Basics - is it a letter? (0) | 2022.04.03 |