By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Complete the code challenge below. Read the instructions carefully and use the integrated editor on the right to write and run your solution.
Before you call a real API, build the logic that makes calling it safe. This challenge is pure, deterministic Python — no network, no key — and it is exactly the code you will reuse in Module 6.
backoff_delay(attempt, base=0.5, cap=8.0) → the wait for a 0-based attempt number: base * 2**attempt, never above cap, rounded to 2 decimals.should_retry(status) → True for 408, 429, 500, 502, 503, 504; False for everything else (including 200, 400, 401, 403, 404).execute_with_retries(codes, max_attempts=3) → simulate calling an API that returns the given status codes in order. Retry while should_retry is true and attempts remain. Return "ok:N" if a 200 was reached on attempt N, otherwise "fail:N" where N is the number of attempts actually made.execute_with_retries([503, 200]) -> attempt 1 gets 503 (retry)
-> attempt 2 gets 200 -> 'ok:2'
execute_with_retries([400]) -> 400 is not retryable -> 'fail:1'
execute_with_retries([503, 503, 503]) -> three attempts, none 200 -> 'fail:3'Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.