A garden weather station logs one air temperature (°C) per hour. Its sensor sometimes fails: then the log holds None, or a marker such as 999 or -999, or some other value that cannot be a real air temperature. Any reading that is None or lies outside -50 to 60 °C (inclusive) is a fault.
Write summarise(readings) that ignores the faults and returns a dictionary with
"valid": how many readings were kept, and"faults": how many were thrown away,"min","max"and"range"(max minus min) of the kept readings,"mean"of the kept readings, as a float.
If no reading is valid, "min", "max", "range" and "mean" are all None.
Examples
Input: readings = [12.5, 13.0, 999, 11.0, None, 14.5, -999]
Output: {"valid": 4, "faults": 3, "min": 11.0, "max": 14.5, "range": 3.5, "mean": 12.75}
Input: readings = [-3, -7, -1]
Output: {"valid": 3, "faults": 0, "min": -7, "max": -1, "range": 6, "mean": -3.6666666666666665}
Input: readings = [None, 999]
Output: {"valid": 0, "faults": 2, "min": None, "max": None, "range": None, "mean": None}
Constraints
0 <= len(readings) <= 10**5- every reading is
None, anintor afloat - numbers are compared with a small tolerance, so
3.5and3.5000000001both count as right
Goals
- Spot impossible values before summarising
- Find the minimum, maximum, range and mean of the values that remain in one pass
- Report how much data was thrown away alongside the summary