Skip to the content

The list average

Problem

Write a function that takes a list of numbers and returns their average: the sum of all of them divided by how many there are. Do not round it: if the average is 1.5, return 1.5.

You cannot divide by zero, so if the list is empty return 0.

Examples

  • [2, 4, 6] → 4

  • [1, 2] → 1.5

  • [10] → 10

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def list_average(numbers):
    pass

JavaScript

function listAverage(numbers) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →