Deviopath › Python

Average Score

Easy · Lists

The average is sum(numbers) / len(numbers). Dividing by zero raises an error, so handle the empty list first. An empty list is "falsy", so if not numbers: catches it.

Write a function average(numbers) that returns the average rounded to 2 decimal places, or 0 for an empty list.

Next: Last N Items