Problem 154063 · easy · Phase 01 Prerequisites & Setup

Running Rainfall Totals

loops · lists · accumulation

A weather station records how much rain fell each day in the list rain. Write running_totals(rain) that returns a new list where entry i is the total rainfall from day 0 up to and including day i.

Examples

Input:  rain = [3, 1, 4]
Output: [3, 4, 8]

Input:  rain = []
Output: []

Constraints

  • 0 <= len(rain) <= 10**5
  • -1000 <= rain[i] <= 1000 (negative values mean a measurement correction)

Goals

  • Build a new list where each entry depends on the sum so far
  • Keep the running total in a variable across iterations
Starting Python…