The Seven O'Clock Average

Data with PythonMedium+10 XP+10

The Seven O'Clock Average

A garden sensor takes per_day temperature readings every day, always at the same times. Its log arrives as one long list of text, like "12.5" or "-999": all of day 0's readings, then all of day 1's, and so on. The list always holds whole days.

When the sensor loses its signal, it doesn't skip a reading. It writes the marker number missing instead.

Task: write slot_average(readings, per_day, slot, missing). slot says which reading of the day you want: 0 is the first reading of each day, 1 the second, and so on. Return the average of that slot's readings across all the days, leaving out any reading equal to missing. Round it to 2 decimal places.

If every reading in that slot is the marker, there's nothing to average. Return None.

Examples

readings = ["6.5", "14.0", "11.2", "7.1", "-999", "12.0", "5.8", "15.5", "10.4"]
per_day = 3
slot = 0
missing = -999
returns 6.47
readings = ["6.5", "14.0", "11.2", "7.1", "-999", "12.0", "5.8", "15.5", "10.4"]
per_day = 3
slot = 1
missing = -999
returns 14.75

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run