How much rain fell in Galway over four days, and on how many did it top 4 mm?
A Galway weather station logs four days of rain, including one completely dry day. How much rain fell altogether, and on how many days did it go above four millimetres? Can you get both answers in one pass through the readings?
You already know how a for loop visits a list. The loop gives you six first, then zero, then four, then eight. Each reading becomes the current value once. The zero is still an item in the list, so it gets its own turn.
Put the four readings in a list and set the total to zero before the loop. Add six to get six. Add zero and it stays at six. Add four to reach ten, then eight to reach eighteen. The value you carry forward after each reading is your running total.
Your running total is nine millimetres when the next day's reading comes in at zero. What should the total be after the loop processes that reading? Pick an answer.
Set both values to zero, then start the loop. You add six and count it because it exceeds four. Zero leaves both unchanged. Four takes the total to ten, but the count stays at one because four equals the limit. Eight takes the total to eighteen and the count to two.
The limit is five millimetres. Read each pair as total, then count. Both start at zero. Add five, but keep the count at zero because five equals the limit. Seven takes you to twelve and one. Zero leaves both unchanged. Nine also exceeds the limit, giving you twenty-one and two.
Now the readings are three, zero, four and six millimetres. The limit is four. Pick the pair that gives the total rainfall first and the number of readings above the limit second.
Compare where the total is set to zero. Inside the loop, each reset wipes out the earlier readings, so the last reading leaves you with eight. Set the total to zero before the loop and each addition builds on the last, giving eighteen.
Write a Python function that takes readings and a limit. Set both values to zero. In the loop, add each reading, then increase the count if the reading exceeds the limit. Return both values after the loop. The test checks that Galway’s readings give eighteen millimetres and a count of two.