Let's create a command-line to-do list manager, a practical project that will help you manage tasks efficiently while reinforcing key programming concepts like functions, file handling, and list manipulation. This application will allow you to view your tasks, add new ones, mark tasks as complete, and save everything to a file so your tasks persist between sessions. It’s a great way to level up your skills, as it combines user interaction, data storage, and modular code design.
The to-do list manager will be a text-based application that runs in the terminal. Users will interact with it through a simple menu, entering commands to perform actions like adding a task, viewing all tasks, marking a task as complete, or exiting the program. Tasks will be stored in a file, ensuring they’re saved even after the program closes. This project introduces real-world programming challenges like reading from and writing to files, handling user input, and organizing code with functions.
This project will help you practice:
When you run the program, it might look like this in the terminal:
=== To-Do List Manager ===
1. View tasks
2. Add task
3. Mark task as complete
4. Exit
Enter your choice (1-4):
Tasks:
1. Buy groceries - Incomplete
2. Finish homework - Complete
3. Call mom - Incomplete
Enter task description: Go for a run
Task added successfully!
Enter task number to mark as complete: 1
Task marked as complete!
Here’s a rough outline of how the code might look:
import json
def load_tasks():
try:
with open("tasks.json", "r") as file:
return json.load(file)
except FileNotFoundError:
return []
def save_tasks(tasks):
with open("tasks.json", "w") as file:
json.dump(tasks, file, indent=4)
def view_tasks(tasks):
if not tasks:
print("No tasks found!")
return
for i, task in enumerate(tasks, 1):
print(f"{i}. {task['description']} - {task['status']}")
def add_task(tasks, description):
tasks.append({"description": description, "status": "Incomplete"})
def mark_complete(tasks, task_number):
if 1 <= task_number <= len(tasks):
tasks[task_number - 1]["status"] = "Complete"
print("Task marked as complete!")
else:
print("Invalid task number!")
def main():
tasks = load_tasks()
while True:
print("\n=== To-Do List Manager ===")
print("1. View tasks")
print("2. Add task")
print("3. Mark task as complete")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
view_tasks(tasks)
elif choice == "2":
description = input("Enter task description: ")
add_task(tasks, description)
save_tasks(tasks)
print("Task added successfully!")
elif choice == "3":
view_tasks(tasks)
try:
task_number = int(input("Enter task number to mark as complete: "))
mark_complete(tasks, task_number)
save_tasks(tasks)
except ValueError:
print("Please enter a valid number!")
elif choice == "4":
save_tasks(tasks)
print("Goodbye!")
break
else:
print("Invalid choice! Please try again.")
if __name__ == "__main__":
main()
Once the core functionality is working, you could add features like:
This to-do list manager is a perfect balance of challenge and practicality. It’s complex enough to stretch your skills but simple enough to complete in a reasonable time. You’ll gain hands-on experience with file I/O, modular programming, and user interaction, which are foundational for building larger applications. Plus, you’ll end up with a tool you can actually use to stay organized!