Overview
This lecture explains how to create a simple console-based to-do list app using Python, covering task management operations through user input.
Setting Up the Project
- Open VS Code and select or create a new folder for your project.
- Create a Python file named
to-do-list.py.
Core App Structure
- Initialize an empty tasks array to store to-do items.
- Use a
while True loop to continually prompt the user for input until they choose to exit.
User Options & Implementation
- Display four options: show tasks, add task, remove task, and exit.
- For each iteration, take the user's menu choice and perform the corresponding action.
Show Tasks
- If the user enters 1, print all tasks in the list.
- Use
enumerate to display tasks with their index numbers.
- If there are no tasks, print "No task present".
Add Task
- If the user enters 2, prompt for a new task using
input.
- If the input is not empty, append the new task to the tasks array.
Remove Task
- If the user enters 3, display the tasks with indices.
- Ask for the index of the task to remove.
- Use
pop to delete the selected task from the array.
Exit
- If the user enters 4, break the while loop to exit the program.
Key Terms & Definitions
- Array (List) — a Python data structure for storing multiple items (tasks).
- Enumerate — a function that returns pairs of an index and the value from an iterable.
- Append — a method to add an item to the end of a list.
- Pop — a method that removes and returns an item at a specified index from a list.
Action Items / Next Steps
- Practice building the app step-by-step in your own Python environment.
- Test all four functionalities: show, add, remove, and exit.
- Explore adding more features, such as task editing or marking tasks as complete.