To-Do List App
BasicBuild your personal task manager in Python
1) Project Overview
This project is a simple to-do list you use in the console (the black-and-white text screen). You can:
- Add new tasks you want to do
- See all your tasks with numbers
- Mark a task as done
- Delete a task you no longer need
- Exit the program
It's like a small personal assistant that remembers your tasks while the program is running.
2) Learning Objectives
By building this project, you will practice:
- Variables and data types (strings, booleans)
- Lists (storing many tasks)
- Dictionaries (keeping task text and done/not-done status together)
- Loops (keep showing the menu until the user exits)
- Functions (organizing code into small, reusable pieces)
- Conditional statements (if/elif/else for choices)
- User input and simple validation (handling mistakes nicely)
- Basic logic and problem-solving
3) Step-by-Step Explanation
Follow these steps to build the app:
- Plan the features
- We need a menu with options: Add, View, Mark Done, Delete, Exit.
- We need a place to store tasks.
- Choose a data structure
- Use a list named tasks.
- Each task will be a dictionary like
{"title": "Do homework", "done": False}. - This way we keep both the text and whether it's done, together.
- Make a function to show the menu
- Print the options 1–5 so the user can choose.
- Make a function to display tasks
- If there are no tasks, tell the user.
- If there are tasks, print them with numbers starting at 1.
- Show a check mark for done tasks.
- Make a function to add a task
- Ask the user for the task text.
- If they type something, add it to the list as not done yet.
- If they type nothing, remind them to enter something.
- Make a function to mark a task as done
- If the list is empty, tell the user.
- Otherwise, show tasks and ask for a number.
- Convert the input to a number, check it's in range, then set done = True.
- Make a function to delete a task
- Similar to marking as done, but remove the selected task from the list.
- Build the main loop
- Keep showing the menu.
- Read the user's choice and call the matching function.
- If the user chooses Exit, say goodbye and stop the loop.
- Test your app
- Try adding, viewing, marking done, deleting, and exiting.
- Try typing wrong inputs to see if the program handles them nicely.
4) Complete and Well-Commented Python Code
You can copy this into a file named todo_app.py and run it.
# Simple To-Do List App (Console Version)
def show_menu():
print("\n====== TO-DO LIST MENU ======")
print("1) Add a task")
print("2) View all tasks")
print("3) Mark a task as done")
print("4) Delete a task")
print("5) Exit")
print("=============================")
def print_tasks(tasks):
"""Show all tasks with numbers and done status."""
if not tasks:
print("\nNo tasks yet. Add your first task!")
return
print("\nYour tasks:")
for i, task in enumerate(tasks, start=1):
# If task["done"] is True, show a check mark ✓, otherwise a space
status = "✓" if task["done"] else " "
print(f"{i}. [{status}] {task['title']}")
def add_task(tasks):
"""Ask the user for a task and add it to the list."""
title = input("\nType your new task: ").strip()
if title == "":
print("Oops! The task cannot be empty.")
return
tasks.append({"title": title, "done": False})
print(f"Added: {title}")
def mark_task_done(tasks):
"""Mark a chosen task as done."""
if not tasks:
print("\nThere are no tasks to mark. Add one first.")
return
print_tasks(tasks)
choice = input("\nEnter the task number to mark as done: ").strip()
# Try to turn the input into a number
try:
index = int(choice) - 1 # user sees 1-based numbers, list uses 0-based
if 0 <= index < len(tasks):
if tasks[index]["done"]:
print(f"Task already done: {tasks[index]['title']}")
else:
tasks[index]["done"] = True
print(f"Marked as done: {tasks[index]['title']}")
else:
print("That number is not in the list.")
except ValueError:
print("Please enter a valid number.")
def delete_task(tasks):
"""Delete a chosen task from the list."""
if not tasks:
print("\nThere are no tasks to delete. Add one first.")
return
print_tasks(tasks)
choice = input("\nEnter the task number to delete: ").strip()
try:
index = int(choice) - 1
if 0 <= index < len(tasks):
removed = tasks.pop(index)
print(f"Deleted: {removed['title']}")
else:
print("That number is not in the list.")
except ValueError:
print("Please enter a valid number.")
def main():
# Our list of tasks; each task is a dictionary with title and done status
tasks = []
print("Welcome to the To-Do List App!")
while True:
show_menu()
choice = input("Choose an option (1-5): ").strip()
if choice == "1":
add_task(tasks)
elif choice == "2":
print_tasks(tasks)
elif choice == "3":
mark_task_done(tasks)
elif choice == "4":
delete_task(tasks)
elif choice == "5":
print("\nGoodbye! You did great today. Keep being organized!")
break
else:
print("Please choose a number from 1 to 5.")
# This line runs the program when you run the file
if __name__ == "__main__":
main()
5) Output Examples
Example session:
====== TO-DO LIST MENU ======
1) Add a task
2) View all tasks
3) Mark a task as done
4) Delete a task
5) Exit
=============================
Choose an option (1-5): 1
Type your new task: Do math homework
Added: Do math homework
====== TO-DO LIST MENU ======
1) Add a task
2) View all tasks
3) Mark a task as done
4) Delete a task
5) Exit
=============================
Choose an option (1-5): 1
Type your new task: Read 20 pages
Added: Read 20 pages
====== TO-DO LIST MENU ======
1) Add a task
2) View all tasks
3) Mark a task as done
4) Delete a task
5) Exit
=============================
Choose an option (1-5): 2
Your tasks:
1. [ ] Do math homework
2. [ ] Read 20 pages
====== TO-DO LIST MENU ======
1) Add a task
2) View all tasks
3) Mark a task as done
4) Delete a task
5) Exit
=============================
Choose an option (1-5): 3
Your tasks:
1. [ ] Do math homework
2. [ ] Read 20 pages
Enter the task number to mark as done: 2
Marked as done: Read 20 pages
====== TO-DO LIST MENU ======
1) Add a task
2) View all tasks
3) Mark a task as done
4) Delete a task
5) Exit
=============================
Choose an option (1-5): 2
Your tasks:
1. [ ] Do math homework
2. [✓] Read 20 pages
====== TO-DO LIST MENU ======
1) Add a task
2) View all tasks
3) Mark a task as done
4) Delete a task
5) Exit
=============================
Choose an option (1-5): 4
Your tasks:
1. [ ] Do math homework
2. [✓] Read 20 pages
Enter the task number to delete: 1
Deleted: Do math homework
====== TO-DO LIST MENU ======
1) Add a task
2) View all tasks
3) Mark a task as done
4) Delete a task
5) Exit
=============================
Choose an option (1-5): 5
Goodbye! You did great today. Keep being organized!
6) Small Exercise (Challenge)
Add an "Edit a task" option
Goal: Let the user change the text of an existing task.
Hints:
- Add a new menu option: "6) Edit a task" (and adjust prompts).
- Create a function
edit_task(tasks)similar todelete_task. - Show the tasks, ask for a task number, and then ask for the new text.
- Replace
tasks[index]["title"]with the new text if it's not empty. - Test it with several tasks.
7) Summary
Great job! You built a complete console app using core Python skills: lists, dictionaries, loops, functions, and user input. These are the building blocks for bigger projects. Keep practicing, try the challenge, and remember: every small project makes you a stronger programmer. Keep going—you've got this!