0
0
Flaskframework~10 mins

Task status monitoring in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start the Flask app.

Flask
if __name__ == '__main__':
    app.[1]()
Drag options to blanks, or click blank then click option'
Astart
Blaunch
Crun
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() or launch() which are not Flask methods.
2fill in blank
medium

Complete the code to define a route for task status.

Flask
@app.route('/status/[1]')
def task_status(task_id):
    return f"Status of task {task_id}"
Drag options to blanks, or click blank then click option'
Atask
Btask_id
Cstatus
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name in the route than in the function parameter.
3fill in blank
hard

Fix the error in the code to return JSON response with task status.

Flask
from flask import jsonify

@app.route('/status/<task_id>')
def task_status(task_id):
    status = {'task_id': task_id, 'status': 'running'}
    return [1](status)
Drag options to blanks, or click blank then click option'
Ajsonify
Bjson
Cjsonify_response
Djson_response
Attempts:
3 left
💡 Hint
Common Mistakes
Using json which is a module, not a Flask response function.
4fill in blank
hard

Fill both blanks to check if a task is complete and return appropriate status.

Flask
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'})
Drag options to blanks, or click blank then click option'
A==
Bjsonify
C!=
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == for checking completion.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering completed tasks.

Flask
completed_tasks = {task_id: status for task_id, status in tasks.items() if status [1] 'complete' and task_id [2] [3]
Drag options to blanks, or click blank then click option'
A==
B!=
C'task_1'
D'task_2'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or wrong task id string.