Loading...
Loading...
A service call is tried at most 3 times. One input line lists the result of each possible try as OK or FAIL, three words separated by spaces.
For each try, in order, print Attempt <k>: failed for FAIL or Attempt <k>: success for OK. Stop after the first success. If all three fail, print Giving up after 3 attempts.
Raise ConnectionError for a failed try and catch it.
OK or FAIL.Example 1
Input
FAIL OK OK
Output
Attempt 1: failed Attempt 2: success
Succeeds on the second try. The third result is never used.
Example 2
Input
FAIL FAIL FAIL
Output
Attempt 1: failed Attempt 2: failed Attempt 3: failed Giving up after 3 attempts
Never succeeds.
Try the problem first. Open one hint at a time.
Loop over the three results with a counter for the attempt number. Raise ConnectionError inside try when the result is FAIL.
Put the success message in else and break. Use the loop else for the giving-up message.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor