📖 Scenario: You are building a simple program to monitor the status of tasks in a project. Each task has a name and a status like 'pending', 'in progress', or 'done'. You want to create a small program that keeps track of tasks and shows how many tasks are done.
🎯 Goal: Build a program that stores tasks in a dictionary, sets a status filter, counts how many tasks are done, and displays the count.
📋 What You'll Learn
Create a dictionary called tasks with exact task names and statuses
Create a variable called status_filter with the value 'done'
Use a list comprehension to create a list of tasks with status matching status_filter
Print the count of tasks that are done
💡 Why This Matters
🌍 Real World
Monitoring task statuses helps teams track progress and identify completed work quickly.
💼 Career
Understanding how to filter and count tasks is useful for building dashboards and status reports in DevOps and project management roles.
Progress0 / 4 steps
1
Create the tasks dictionary
Create a dictionary called tasks with these exact entries: 'task1': 'pending', 'task2': 'done', 'task3': 'in progress', 'task4': 'done'
Flask
Hint
Use curly braces to create a dictionary with keys as task names and values as their statuses.
2
Set the status filter
Create a variable called status_filter and set it to the string 'done'
Flask
Hint
Just assign the string 'done' to the variable status_filter.
3
Filter tasks by status
Use a list comprehension to create a list called done_tasks that contains the names of tasks from tasks where the status equals status_filter
Flask
Hint
Use tasks.items() to get task and status pairs, then filter by status_filter.
4
Print the count of done tasks
Print the number of tasks in done_tasks using print(len(done_tasks))
Flask
Hint
Use len() to get the count of items in the list and print it.
Practice
(1/5)
1. What is the main purpose of task status monitoring in a Flask application?
easy
A. To store user login credentials securely
B. To speed up the Flask server response time
C. To let users see the progress of background jobs
D. To automatically restart the Flask app on errors
Solution
Step 1: Understand task status monitoring
Task status monitoring is about showing users how background jobs are progressing.
Step 2: Identify the correct purpose
Among the options, only letting users see job progress matches the purpose.
Final Answer:
To let users see the progress of background jobs -> Option C
Quick Check:
Task status monitoring = show job progress [OK]
Hint: Task status monitoring shows job progress to users [OK]
Common Mistakes:
Confusing task monitoring with server speed optimization
Thinking it manages user authentication
Assuming it restarts the app automatically
2. Which Flask route method is best to check the status of a running background task?
easy
A. POST
B. GET
C. DELETE
D. PUT
Solution
Step 1: Understand HTTP methods for status checking
GET is used to retrieve information without changing server state.
Step 2: Match method to task status check
Checking task status is a read operation, so GET is appropriate.
Final Answer:
GET -> Option B
Quick Check:
Check status = GET request [OK]
Hint: Use GET to fetch status without changing data [OK]
Common Mistakes:
Using POST which changes data
Choosing DELETE which removes data
Using PUT which updates data
3. Given this Flask code snippet, what will be the output when accessing /status/task1 if tasks = {'task1': 'running'}?