Bird
0
0

What will be the output of this Flask route when accessing /status/999 if the task status dictionary is {'123': 'completed'}?

medium📝 Command Output Q5 of 15
Flask - Background Tasks
What will be the output of this Flask route when accessing /status/999 if the task status dictionary is {'123': 'completed'}?
@app.route('/status/')
def status(task_id):
    statuses = {'123': 'completed'}
    return statuses.get(task_id, 'unknown')
Aunknown
BNone
Ccompleted
DError 500
Step-by-Step Solution
Solution:
  1. Step 1: Identify the task_id from URL

    The URL provides task_id as '999'.
  2. Step 2: Check dictionary for key '999'

    Key '999' is not in statuses, so get returns default 'unknown'.
  3. Final Answer:

    unknown -> Option A
  4. Quick Check:

    Missing key returns default value [OK]
Quick Trick: Missing dict keys return default in get() method [OK]
Common Mistakes:
MISTAKES
  • Assuming 'completed' is returned for unknown keys
  • Expecting None instead of default string
  • Thinking it causes server error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes