PythiloLesson 1 of 8 · progress kept in this browser

Make retry delays predictable and bounded

Retries need a policy rather than a sleep scattered through the code. A pure function can produce the planned delays without actually waiting or sending requests. Exponential backoff increases the gap after each failure, and a cap prevents unbounded pauses. Random jitter can be added by the caller, using an injected random source when reproducible tests matter.

delay = 0.25
for attempt in range(3):
    print(delay)
    delay = min(1.0, delay * 2)
Your task

Write retry_delays(attempts, base, cap). Return attempts delays, starting at base and doubling up to cap. attempts must be nonnegative and base and cap must be positive; otherwise raise ValueError. The first delay is also capped.