Sponsored Reserved space — layout preview until AdSense is connected
medium +28 pts

Retry decorator

Transient failure recovery.

Implement `retry(times: int)` decorator factory. On each call, if the wrapped function raises an exception, retry up to `times` attempts total. Re-raise the last exception if all attempts fail.

Constraints

times ≥ 1.

Example

@retry(times=3)
def flaky():
    import random
    if random.random() < 0.8: raise RuntimeError
    return 'ok'
28 points ~25 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Loop `for _ in range(times): try: return fn(); except: save exc`. Raise after loop.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected