Mini Project: A To-Do App

Site Admin · 11 Sep 2026 · 8 views

Mini Project: A To-Do App

Bringing It All Together

Everything you have learned so far - variables, collections, control flow, functions, and files - combines in this project: a command-line to-do app. The app prompts the user, stores tasks in a file, and lets the user add, list, complete, and remove tasks. It is small enough to type out and understand fully, and every part ties back to a topic from this tutorial.

The Project Plan

The app keeps tasks in a list. Each item is a dictionary with a description and a completed flag. A file stores the tasks between runs so they survive when the program exits. The program loops forever, showing a menu and acting on the user's choice until they choose to quit.

import json

def load_tasks(filename="tasks.json"):
    try:
        with open(filename) as f:
            return json.load(f)
    except FileNotFoundError:
        return []

Core Functions

Each action becomes its own function, which keeps the logic easy to follow and test. Adding a task appends a dictionary, listing prints each task with its status, and completing marks a task as done by its number.

def add_task(tasks, description):
    tasks.append({"description": description, "done": False})

def show_tasks(tasks):
    for index, task in enumerate(tasks, start=1):
        mark = "[x]" if task.get("done") else "[ ]"
        print(str(index) + ". " + mark + " " + task["description"])

The Main Loop

def main():
    tasks = load_tasks()
    while True:
        print("1) Add  2) Show  3) Done  4) Quit")
        choice = input("Choose: ")
        if choice == "1":
            add_task(tasks, input("Describe the task: "))
        elif choice == "2":
            show_tasks(tasks)
        elif choice == "3":
            show_tasks(tasks)
            index = int(input("Which number is done? ")) - 1
            tasks[index]["done"] = True
        else:
            break
    with open("tasks.json", "w") as f:
        json.dump(tasks, f)

if __name__ == "__main__":
    main()

The repeated menus and input() calls exercise the control flow you learned several posts ago. The if __name__ == "__main__" line runs main() only when the script is executed directly, which lets other files import its functions without side effects.

What You Just Built

This single script uses functions for structure, a list of dictionaries for data, a menu loop for control flow, JSON and file handling for persistence, and try/except for the missing file on the very first run. Run it, add a few tasks, quit, and start it again: your tasks are still there.

Natural next steps: add a due date to each task, validate input before using it, or sort tasks by status. Every extension exercises the same fundamentals you met in this tutorial.

Key Points

  • A complete project combines variables, collections, loops, functions, and files.
  • JSON encodes data as text, which makes persistence simple with the json module.
  • try/except handles a missing data file on the first run.
  • Keeping each action in a function keeps the script readable and testable.
  • Build one feature at a time and test it before moving on.
Share this post:

Comments (0)

Please login or register to comment.