📌 Project Overview
In this project, you will create a simple To-Do List application. Users can add, view and remove tasks.
- Creating and using lists
- Adding items with append()
- Removing items
- Creating functions
- Using while loops
- Using conditional statements
⚙️ To-Do List Features
Step 1: Create a Task List
Start with an empty list to store tasks.
tasks = []
Step 2: Add a Task
The append() method adds a new task to the list.
task = input("Enter a task: ")
tasks.append(task)
Step 3: Display Tasks
Use a loop to display all the tasks.
for i, task in enumerate(tasks, 1):
print(i, task)
Step 4: Remove a Task
Use pop() to remove a task using its position.
task_number = int(
input("Enter task number to remove: ")
)
tasks.pop(task_number - 1)
🚀 Complete Python Code
tasks = []
def show_tasks():
if len(tasks) == 0:
print("No tasks available.")
else:
print("\nYour Tasks:")
for i, task in enumerate(tasks, 1):
print(i, ".", task)
while True:
print("\n===== TO-DO LIST =====")
print("1. Add Task")
print("2. View Tasks")
print("3. Remove Task")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
task = input("Enter task: ")
tasks.append(task)
print("Task added successfully!")
elif choice == "2":
show_tasks()
elif choice == "3":
show_tasks()
if len(tasks) > 0:
task_number = int(
input("Enter task number to remove: ")
)
if 1 <= task_number <= len(tasks):
removed_task =
tasks.pop(task_number - 1)
print(
"Removed:",
removed_task
)
else:
print("Invalid task number.")
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid choice.")
⚠️ Important Python Formatting
In the complete code above, the assignment of
removed_task should stay on one line.
removed_task = tasks.pop(task_number - 1)
💻 Example Output
===== TO-DO LIST ===== 1. Add Task 2. View Tasks 3. Remove Task 4. Exit Enter your choice: 1 Enter task: Complete Python homework Task added successfully! ===== TO-DO LIST ===== Enter your choice: 2 Your Tasks: 1 . Complete Python homework
🧠 Mini Challenge
Try improving the To-Do List by adding:
- Mark a task as completed
- Add task priority
- Search for a task
- Save tasks to a file
- Load tasks when the program starts
📝 Try the To-Do List
Add your tasks, mark them as completed, or delete them.