Bird
0
0

Given this Python retry function, what will be printed if the API always returns status code 503?

medium📝 Predict Output Q5 of 15
Rest API - Webhooks and Events

Given this Python retry function, what will be printed if the API always returns status code 503?

def retry_api_call():
    for _ in range(3):
        response = {'status_code': 503}
        if response['status_code'] == 200:
            print('Success')
            return
    print('Failed after retries')
retry_api_call()
ANo output
BSuccess
CFailed after retries
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Check loop and response status

    Loop runs 3 times, response status is always 503, so condition for success never met.
  2. Step 2: Determine printed output

    Since success condition never true, loop ends and prints 'Failed after retries'.
  3. Final Answer:

    Failed after retries -> Option C
  4. Quick Check:

    Loop with no success prints failure [OK]
Quick Trick: If success condition never met, prints failure after loop [OK]
Common Mistakes:
MISTAKES
  • Assuming 503 is success
  • Expecting no output
  • Thinking code throws error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes