Build a Simple To-Do App in Python (Step by Step)


 

Build a Simple To-Do App in Python (Step by Step)

Introduction

If you’re learning Python, the best way to practice is by building small, real-world projects.

One of the easiest and most useful projects is a To-Do List Application. This project teaches you about lists, functions, user input, and control flow.

In this tutorial, we’ll build a text-based To-Do app in Python, step by step.

By the end, you’ll have a program where you can:
✔ Add tasks
✔ View tasks
✔ Mark tasks as completed
✔ Delete tasks


 Step 1: Plan the Features

Our To-Do List App will include these options:

  1. Add a new task

  2. View all tasks

  3. Mark a task as completed

  4. Delete a task

  5. Exit the program


 Step 2: Python Code

# Simple To-Do App in Python

tasks = []  # Empty list to store tasks

def show_menu():
    print("\n===== TO-DO LIST APP =====")
    print("1. Add Task")
    print("2. View Tasks")
    print("3. Mark Task as Completed")
    print("4. Delete Task")
    print("5. Exit")

def add_task():
    task = input("Enter your task: ")
    tasks.append({"task": task, "done": False})
    print(f" Task '{task}' added successfully!")

def view_tasks():
    if not tasks:
        print(" No tasks yet!")
        return
    print("\nYour Tasks:")
    for i, t in enumerate(tasks, 1):
        status = " Done" if t["done"] else " Not Done"
        print(f"{i}. {t['task']} [{status}]")

def mark_completed():
    view_tasks()
    try:
        num = int(input("Enter task number to mark completed: "))
        tasks[num-1]["done"] = True
        print(f" Task '{tasks[num-1]['task']}' marked as completed!")
    except (IndexError, ValueError):
        print(" Invalid choice!")

def delete_task():
    view_tasks()
    try:
        num = int(input("Enter task number to delete: "))
        removed = tasks.pop(num-1)
        print(f" Task '{removed['task']}' deleted!")
    except (IndexError, ValueError):
        print(" Invalid choice!")

# Main loop
while True:
    show_menu()
    choice = input("Enter choice (1-5): ")
    
    if choice == "1":
        add_task()
    elif choice == "2":
        view_tasks()
    elif choice == "3":
        mark_completed()
    elif choice == "4":
        delete_task()
    elif choice == "5":
        print(" Exiting To-Do App. Goodbye!")
        break
    else:
        print(" Invalid option, try again!")

Step 3: Sample Output

===== TO-DO LIST APP =====
1. Add Task
2. View Tasks
3. Mark Task as Completed
4. Delete Task
5. Exit
Enter choice (1-5): 1
Enter your task: Finish homework
 Task 'Finish homework' added successfully!
Your Tasks:
1. Finish homework [ Not Done]

Step 4: What You Learned

  • How to use lists of dictionaries for storing structured data

  • Creating functions to organize code

  • Handling user input & exceptions

  • Building a menu-driven Python application


Continue updating above code,

Enhance your To-Do App with these ideas:

  • Save tasks to a file (so they remain even after closing the program)

  • Add priority levels or deadlines

  • Build a GUI version using Tkinter


 Challenge for You

Modify this app so that it saves tasks into a text file and loads them when restarted.

 Share your code version in the comments below!


Final Summary

This Python To-Do List project is a great way to start your coding journey. With just a few lines of code, you built a practical app that can be extended into bigger projects.





Comments