In the journey of learning Python, one of the best ways to strengthen your programming skills is by building small, practical projects. These projects not only help you apply theoretical concepts but also give you hands-on experience in solving real-world problems.
In this article, we will see To-Do List (CLI). A command-line interface (CLI) To-Do List is a perfect beginner-friendly project that teaches you how to work with lists, loops, functions, and user input in Python.
By the end of this article, you will be able to build your own interactive To-Do List application that allows users to add, view, and delete tasks — all from the terminal. We will also walk through the sample code, break it down into understandable chunks, and showcase what the output looks like when you run the program.
The problem we are solving is simple: Create a command-line To-Do List app that lets users add, view, and delete tasks during a session.
While this may sound basic, it actually covers some essential programming concepts, including:
By creating this project, you’ll develop important Python skills such as:
These are foundational skills that you will use in more advanced Python projects later on.
The first step is to create an empty list that will store all tasks. In Python, we can easily manage tasks using a list because it supports dynamic addition and removal of items.
todo_list = []
Here, todo_list is an empty list that will hold all the tasks we add.
We want to give the user the ability to see what tasks have been added. For this, we will write a function called show_tasks().
def show_tasks():
if not todo_list:
print("No tasks yet.")
else:
for i, task in enumerate(todo_list, 1):
print(f"{i}. {task}")
Code language: PHP (php)
Explanation:
if not todo_list:. If true, we display “No tasks yet.”enumerate() to loop through the list and print each task with a number starting from 1.Next, we allow the user to add tasks. For this, we define the add_task(task) function.
def add_task(task):
todo_list.append(task)
print("Task added.")
Code language: PHP (php)
Explanation:
append() is used to add a task to the list.Users should also be able to delete tasks. For this, we will write the delete_task(index) function.
def delete_task(index):
if 0 < index <= len(todo_list):
removed = todo_list.pop(index - 1)
print(f"Deleted: {removed}")
else:
print("Invalid task number.")
Code language: PHP (php)
Explanation:
pop(index-1) to remove the task at that position.Now that we have functions for viewing, adding, and deleting tasks, we need a menu system that continuously runs until the user exits.
while True:
print("\n=== To-Do List ===")
print("1. View Tasks")
print("2. Add Task")
print("3. Delete Task")
print("4. Exit")
choice = input("Choose an option (1-4): ")
if choice == '1':
show_tasks()
elif choice == '2':
task = input("Enter task: ")
add_task(task)
elif choice == '3':
show_tasks()
try:
idx = int(input("Enter task number to delete: "))
delete_task(idx)
except ValueError:
print("Please enter a valid number.")
elif choice == '4':
print("Goodbye!")
break
else:
print("Invalid option.")
Code language: PHP (php)
Explanation:
while True: keeps the program running until the user chooses to exit.Here’s the full Python code for the project:
todo_list = []
def show_tasks():
if not todo_list:
print("No tasks yet.")
else:
for i, task in enumerate(todo_list, 1):
print(f"{i}. {task}")
def add_task(task):
todo_list.append(task)
print("Task added.")
def delete_task(index):
if 0 < index <= len(todo_list):
removed = todo_list.pop(index - 1)
print(f"Deleted: {removed}")
else:
print("Invalid task number.")
while True:
print("\n=== To-Do List ===")
print("1. View Tasks")
print("2. Add Task")
print("3. Delete Task")
print("4. Exit")
choice = input("Choose an option (1-4): ")
if choice == '1':
show_tasks()
elif choice == '2':
task = input("Enter task: ")
add_task(task)
elif choice == '3':
show_tasks()
try:
idx = int(input("Enter task number to delete: "))
delete_task(idx)
except ValueError:
print("Please enter a valid number.")
elif choice == '4':
print("Goodbye!")
break
else:
print("Invalid option.")
Code language: PHP (php)
Here’s how the program looks when you run it in the terminal:
=== To-Do List ===
1. View Tasks
2. Add Task
3. Delete Task
4. Exit
Choose an option (1-4): 2
Enter task: Learn Python
Task added.
=== To-Do List ===
1. View Tasks
2. Add Task
3. Delete Task
4. Exit
Choose an option (1-4): 1
1. Learn Python
=== To-Do List ===
1. View Tasks
2. Add Task
3. Delete Task
4. Exit
Choose an option (1-4): 2
Enter task: Practice Coding
Task added.
=== To-Do List ===
1. View Tasks
2. Add Task
3. Delete Task
4. Exit
Choose an option (1-4): 1
1. Learn Python
2. Practice Coding
=== To-Do List ===
1. View Tasks
2. Add Task
3. Delete Task
4. Exit
Choose an option (1-4): 3
1. Learn Python
2. Practice Coding
Enter task number to delete: 1
Deleted: Learn Python
=== To-Do List ===
1. View Tasks
2. Add Task
3. Delete Task
4. Exit
Choose an option (1-4): 1
1. Practice Coding
=== To-Do List ===
1. View Tasks
2. Add Task
3. Delete Task
4. Exit
Choose an option (1-4): 4
Goodbye!
Code language: PHP (php)

This interaction demonstrates how you can add multiple tasks, view them, delete tasks by their number, and exit the application.