Task model
- Python course
- Beginner
- Lesson 83/116
- 6 min
Design the Task class.
Project: Todo CLI
In this project you will build a Todo CLI (to-do app) step by step. Create a task list, add tasks, list them and complete them.
First we design the data model. In the simplest form we can store tasks in a list. Each task is a string title.
Each lesson in the project builds on the previous one's solution; so the code grows piece by piece. This approach is close to how real-world projects work.
An empty task list
As the data model we use an empty list:
tasks = []
print(tasks) # []This list is the heart of our app. Tasks will be added here, listed from here and completed here. All functions share this list.
We start simple and grow the project step by step; this is a good software development method.
Practice Print the empty list
Assign an empty list to tasks. Then print it with print(tasks).
Starter code
# Todo CLI - bos gorev listesiSample solution
tasks = []
print(tasks)Expected output
[]
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does the Todo CLI need first?
- A graphical interface
- A task list (tasks) Correct answer
- A database
- A server
Explanation: First we need a list to hold the tasks.
2 Complete the empty list
tasks = ____
print(tasks)
tasks = []
print(tasks)
Explanation: tasks = [] assigns an empty list.
3 Match the Todo CLI steps
| Term | Meaning |
|---|---|
tasks = [] |
Empty list |
print(tasks) |
|
add_task |
Add task |
list_tasks |
List tasks |