Introduction

A To-Do List application is a simple yet practical project for learning Python. In this guide, we'll explore how to create a Python To-Do List application that allows users to add, view, and manage tasks. We'll provide sample code to demonstrate the process.


Prerequisites

Before you start building a Python To-Do List application, ensure you have the following prerequisites:

  • Python installed on your system.
  • Basic knowledge of Python programming.

Creating the To-Do List

Let's create a basic To-Do List application using Python with a simple text-based interface. Users can add tasks, view their tasks, and mark tasks as completed.

# Create an empty list to store tasks
tasks = []
# Function to add a task
def add_task(task):
tasks.append(task)
print("Task added: " + task)
# Function to view all tasks
def view_tasks():
print("Tasks:")
for index, task in enumerate(tasks):
print(f"{index + 1}. {task}")
# Function to mark a task as completed
def complete_task(index):
if 0 <= index < len(tasks):
completed_task = tasks.pop(index)
print("Task completed: " + completed_task)
else:
print("Invalid task index")
# Main loop
while True:
print("\nTo-Do List Menu:")
print("1. Add Task")
print("2. View Tasks")
print("3. Complete Task")
print("4. Quit")
choice = input("Enter your choice: ")
if choice == "1":
task = input("Enter the task: ")
add_task(task)
elif choice == "2":
view_tasks()
elif choice == "3":
index = int(input("Enter the task number to complete: ")) - 1
complete_task(index)
elif choice == "4":
break
else:
print("Invalid choice")

Conclusion

Building a Python To-Do List application is a great way to practice Python programming and data manipulation. You can expand this project by adding features like saving tasks to a file, setting deadlines, or creating a graphical user interface (GUI).