runtime
67 / 500
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.

Inputhighs, a list of daily highs
Printsfor 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 data
Examples[6.7, 7.2, 3.3, 7.2, 3.9, -2.1] → 5.7, 5.9, 4.8, 3.0; [1, 2] → not enough data
Expected output4 lines
  1. 15.7
  2. 25.9
  3. 34.8
  4. 43.0

Loading your progress…

A three-day moving average — Python practice · Runtime