Bird
0
0

What will be the response when accessing /task_status/42 given this Flask route and task_states = {'42': 'failed'}?

medium📝 Command Output Q4 of 15
Flask - Background Tasks
What will be the response when accessing /task_status/42 given this Flask route and task_states = {'42': 'failed'}?
@app.route('/task_status/<task_id>')
def task_status(task_id):
    task_states = {'42': 'failed'}
    return task_states.get(task_id, 'not found')
A404 Not Found error
B"not found"
C"failed"
D500 Internal Server Error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the route

    The route returns the value from task_states dictionary for the given task_id.
  2. Step 2: Check the dictionary

    Since task_id is '42' and exists in the dictionary with value 'failed', it returns 'failed'.
  3. Final Answer:

    "failed" -> Option C
  4. Quick Check:

    Key exists in dict, returns value [OK]
Quick Trick: Dictionary get returns value if key exists [OK]
Common Mistakes:
MISTAKES
  • Assuming a 404 error is returned automatically
  • Confusing return value with HTTP status codes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes