How to Create a To-Do List using Python.
How to Make a To-Do List Using Python - Step-by-Step Guide
Looking for a simple Python project to practice your skills? Learn how to build a to-do list using Python. This beginner-friendly tutorial will walk you through every step to create a functional task manager using basic Python code.
Why Build a To-Do List in Python?
Creating a to-do list app in Python is a practical way to understand lists, functions, and user input. It’s also a great stepping stone toward more advanced projects like GUI or web-based apps.
Step 1: Set Up Your Python File
Start by opening your favorite code editor and creating a new Python file. Name it something like todo.py
.
Step 2: Python Code for To-Do List
Here's the complete code for a basic command-line to-do list:
todo_list = []
def show_menu():
print("\nTo-Do List Menu:")
print("1. View To-Do List")
print("2. Add Task")
print("3. Remove Task")
print("4. Exit")
def view_list():
if not todo_list:
print("Your to-do list is empty.")
else:
for i, task in enumerate(todo_list, 1):
print(f"{i}. {task}")
def add_task():
task = input("Enter the task: ")
todo_list.append(task)
print("Task added.")
def remove_task():
view_list()
try:
task_num = int(input("Enter the task number to remove: "))
removed = todo_list.pop(task_num - 1)
print(f"Removed: {removed}")
except (IndexError, ValueError):
print("Invalid task number.")
while True:
show_menu()
choice = input("Choose an option (1-4): ")
if choice == '1':
view_list()
elif choice == '2':
add_task()
elif choice == '3':
remove_task()
elif choice == '4':
print("Goodbye!")
break
else:
print("Invalid choice. Try again.")
Step 3: Run the Script
Save the file and run it using a terminal or command prompt:
python todo.py
Conclusion
That’s it! You've built a basic Python to-do list app. This project helps you reinforce essential programming skills and opens the door to more advanced development like building GUIs with Tkinter or web apps with Flask.
Want more beginner projects like this? Check out our Python tutorials to keep learning!
Comments
Post a Comment