Complete the code to start the Flask app.
if __name__ == '__main__': app.[1]()
start() or launch() which are not Flask methods.The run() method starts the Flask application server.
Complete the code to define a route for task status.
@app.route('/status/[1]') def task_status(task_id): return f"Status of task {task_id}"
The route uses task_id as a variable part of the URL to identify the task.
Fix the error in the code to return JSON response with task status.
from flask import jsonify @app.route('/status/<task_id>') def task_status(task_id): status = {'task_id': task_id, 'status': 'running'} return [1](status)
json which is a module, not a Flask response function.The jsonify() function converts a Python dictionary to a JSON response in Flask.
Fill both blanks to check if a task is complete and return appropriate status.
def check_task(task_id): if tasks[task_id] [1] 'complete': return [2]({'task_id': task_id, 'status': 'done'}) else: return jsonify({'task_id': task_id, 'status': 'running'})
!= instead of == for checking completion.Use == to compare status and jsonify to return JSON response.
Fill all three blanks to create a dictionary comprehension filtering completed tasks.
completed_tasks = {task_id: status for task_id, status in tasks.items() if status [1] 'complete' and task_id [2] [3]The comprehension filters tasks with status 'complete' and excludes 'task_1'.
