Drill

ProblemsPython › payments

Should this call be retried

mediumpaymentsPython

The gateway client decides whether a failed call is worth trying again, or whether retrying would only make things worse.

should_retry(status: int, attempt: int) → bool

Solve it in the editor →

Where you start

def should_retry(status: int, attempt: int) -> bool:
    

Worked examples

CallResult
should_retry(500, 1)True
should_retry(429, 2)True
should_retry(503, 3)False
should_retry(404, 1)False

Hint

Deal with the attempt ceiling first, then the status.

Reference solution in Python
def should_retry(status: int, attempt: int) -> bool:
    if attempt < 1 or attempt >= 3:
        return False
    return status == 429 or 500 <= status <= 599

The same problem in another language

More payments problems in Python