question 67 Lists & Tuples · medium
A three-day moving average
Daily highs jump around, so a weather chart smooths them with a three-day moving average: for each day from the third onward, the average of that day and the two days before it. Print one average per line with one decimal. If there are fewer than three readings, print not enough data.
Input
highs, a list of daily highsPrintsfor each position i from 2 to the end, the average of
highs[i - 2], highs[i - 1] and highs[i], with one decimal; or not enough dataExamples
[6.7, 7.2, 3.3, 7.2, 3.9, -2.1] → 5.7, 5.9, 4.8, 3.0; [1, 2] → not enough dataExpected output4 lines
- 15.7
- 25.9
- 34.8
- 43.0