반응형
Find Mean
Find the mean (average) of a list of numbers in an array.
Information
To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list.
For an example list of 1, 3, 5, 7
- Add all of the numbers
1+3+5+7 = 16
- Divide by the number of values in the list. In this example there are 4 numbers in the list.
16/4 = 4
- The mean (or average) of this list is 4
Solution:
def get_sum(func):
def wrapper(nums):
return func(sum(nums), len(nums))
return wrapper
@get_sum
def find_average(sum, count):
return sum / count if count else 0
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0920. Difference of Volumes of Cuboids (0) | 2022.09.20 |
---|---|
0919. Cat years, Dog years (0) | 2022.09.19 |
0917. Largest pair sum in array (0) | 2022.09.17 |
0916. Do you speak "English"? (0) | 2022.09.16 |
0915. Beginner - Reduce but Grow (0) | 2022.09.15 |