daco2020 2022. 4. 7. 00:29
반응형

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.

 

 

 

반응형