Exercise: Computing Average
Leer en Español | Solve Online
Background/Motivation
The arithmetic mean, often simply called the average, is one of the most common statistical measures. It provides a central value for a set of numbers and is used in everything from school grades to scientific research. In programming, calculating an average is a fundamental exercise to practice the accumulator pattern and handling collections of data.
The Task
Implement a function list_average(numbers: list[float]) -> float that returns the arithmetic mean of a list of numbers.
Specifications
- Function Name:
list_average - Arguments:
numbers(list of float) - Return Type:
float - Expected Output: The sum of all elements divided by the number of elements. If the list is empty, return
0.0.
Constraints
- $0 \le \text{len(numbers)} \le 10^5$
- The numbers can be integers or floats.
Example
Instructions
- Open
exercises/list_average/solution.py. - Implement the
list_averagefunction. - Change
SUBMIT = FalsetoSUBMIT = Trueat the top of the file when you are ready to be graded. - Run
python solution.pylocally to verify your solution with the built-in self-tests.