Back to Practice
#0180

Running Average Stream

MediumPython25 min20 XP

Problem

Given a list of numbers, return a list where each position contains the average of all values seen so far.

Why This Matters

Streaming averages appear in dashboards, logs, sensors, and online learning where recomputing from scratch is wasteful.

Function Signature

def running_average(values):

Examples

Example 1
Input[10, 20, 30]
Output[10.0, 15.0, 20.0]

The averages are 10/1, 30/2, and 60/3.

Constraints

  • Return the exact requested result.
  • Handle common edge cases.
  • Keep the solution readable before optimizing.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[10, 20, 30]
Expected[10.0, 15.0, 20.0]

The averages are 10/1, 30/2, and 60/3.

Hidden Test Categories
minimal inputrepeated valueslarger realistic input