Python program: A to-do list in the terminal
Manage a to-do list: add, complete and show tasks (a longer version is in the course's projects lesson).
The code
tasks = [] def add(title): tasks.append({"title": title, "done": False}) def complete(n): tasks[n - 1]["done"] = True def show(): for i, t in enumerate(tasks, 1): print(f"{i}. [{'x' if t['done'] else ' '}] {t['title']}") add("Learn loops") add("Do the exercises") add("Build a project") complete(1) show()
Output
1. [x] Learn loops 2. [ ] Do the exercises 3. [ ] Build a project
How it works
A list of dictionaries holds the tasks, and each action is a small function. The First Projects lesson extends this to save tasks to a file.
Python features used
Learn the ideas behind it in the free lesson Py-Projects.