Test a Safe Average
Write the tests · Beginner · about 8 min
average(numbers) returns the mean of a list of numbers: their sum divided by how many there are. For an empty list it returns 0 instead of failing.
Write test_ functions with assert that pass on a correct version and fail on broken ones.
Examples
average([2, 4, 6]) # 4.0 average([1, 2]) # 1.5 average([]) # 0
def test_three_numbers():
assert average([2, 4, 6]) == 4
The solution opens after your first Check.