Essential storage keeps sign-in and learning features working. Google Analytics measures visits; Microsoft Clarity records interactions to help us improve usability. Both are optional and stay off until you choose. Read our privacy policy.
Model a retry result contract coding exercise | SovranCode
Call an operation up to attempts times and return a result dictionary containing ok, value or error, and attempts_used. Do not retry KeyboardInterrupt or SystemExit.
Requirements
Reject attempts below 1
Catch Exception, not BaseException
Return the final error text
Show a hint
Write down the input contract and the failure cases before coding.
tests
Loads Python in an isolated browser worker, then runs your function
RUNTIME OUTPUT
Ready to run the file open above.
LEARN FROM THE SOLUTION
Why the solution works.
A retry helper is a boundary between unreliable work and its caller. Catching Exception leaves process-control exceptions alone, while the stable result shape lets UI or command-line code report success and failure without inspecting exception types.
What this exercise teaches
Exceptions
Retry policies
API contracts
A PRACTICAL PLAN
Work through Model a retry result contract with intent.
Translate the contract.Turn the requirements into a short checklist before editing your-solution.py.
Use the example as evidence.Predict the result for the supplied input, then add one boundary case such as an empty value, a limit, or unexpected input.
Review the implementation.Compare your choices against solution.py only after a real attempt.
EXERCISE FAQ
Before you move on.
What does “Model a retry result contract” teach?
This advanced Python exercise focuses on Exceptions, Retry policies, API contracts. Its requirements define the exact behavior to implement before you write code.
How should I validate this Python solution?
Open your-solution.py and select Run code. The browser loads Python in an isolated worker and runs your function against the visible tests.
When should I open the reference solution?
Attempt Model a retry result contract first. Then open the read-only solution file to compare the contract, edge-case handling, and implementation choices—not simply to copy the final code.