Smooth the Week

Data with PythonEasy+10 XP+10

Smooth the Week

A café counts its visitors every day. The numbers jump around, so the owner wants a rolling average to see the trend.

Task: write smoothed(visitors, window).

  • visitors is a list of daily counts, oldest first. window is a whole number, at least 1.
  • Return the rolling average over window days, as a list of floats rounded to 1 decimal place, oldest first.
  • Leave out the first days where the window isn't full yet. So the list has len(visitors) - window + 1 values.
  • If window is bigger than the number of days, return an empty list.

Examples

visitors = [120, 95, 180, 110, 60, 210, 130]
window = 3
returns [131.7, 128.3, 116.7, 126.7, 133.3]
visitors = [10, 20, 30, 40]
window = 2
returns [15.0, 25.0, 35.0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run