Practical Python Mini Project: Build a Personal To-Do List App in 100 Lines of Code, Achievable for Beginners

Every morning, as soon as I open my eyes, various to-do items flood in like a tide:

In the morning, I need to complete the project report, in the afternoon, I have to attend a team meeting, and in the evening, I must remember to prepare a birthday gift for my family…

There are so many tasks that it can be overwhelming, and I fear missing something important.

Don’t worry, today I will guide you to create a dedicated to-do list manager using Python. You don’t need advanced technical skills or a complex development environment; just basic knowledge of Python syntax will allow you to complete a practical personal task management tool in 100 lines of code!

Part One: Say Goodbye to Chaos, Welcome Order – Why You Need a Dedicated Task Manager

In this age of information overload, we deal with countless tasks every day. Paper notes are easy to lose, and mobile apps are often too complicated. It’s time to create a task manager that perfectly fits your habits.

Three major pain points of traditional methods:

Paper lists are easy to lose and hard to search.

Generic app features are redundant and lack focus.

Data cannot be controlled independently, leading to a lack of security.

Our Python solution will bring:

A clean and intuitive interface, with straightforward operations.

Features that precisely match your needs, rejecting unnecessary designs.

Local data storage, ensuring complete privacy protection.

Imagine opening the terminal to see all your tasks for today, checking them off as you complete them, and receiving automatic reminders for important items – this is the digital assistant we aim to create!

Part Two: Building from Scratch – Perfect Implementation of Four Core Functions

Let’s get started and build this practical task manager with less than 100 lines of code.

First, set up the basic framework:

class TaskManager:
    def __init__(self):
        self.tasks = []
        self.load_tasks()

    def load_tasks(self):
        try:
            with open('tasks.txt', 'r', encoding='utf-8') as f:
                for line in f:
                    if line.strip():
                        task_data = line.strip().split('|')
                        self.tasks.append({
                            'id': len(self.tasks) + 1,
                            'content': task_data[0],
                            'status': task_data[1] if len(task_data) > 1 else 'Pending'
                        })
        except FileNotFoundError:
            self.tasks = []

Next, implement the core functions:

def add_task(self, task_content):
    if task_content.strip():
        new_task = {
            'id': len(self.tasks) + 1,
            'content': task_content,
            'status': 'Pending'
        }
        self.tasks.append(new_task)
        self.save_tasks()
        print(f"Task added: {task_content}")
    else:
        print("Task content cannot be empty")


def show_tasks(self):
    if not self.tasks:
        print("No tasks available")
        return
    print("\nCurrent task list:")
    for task in self.tasks:
        status_icon = "✓" if task['status'] == 'Completed' else "○"
        print(f"{task['id']}. [{status_icon}] {task['content']}")

Finally, enhance the task management functionality:

def complete_task(self, task_id):
    for task in self.tasks:
        if task['id'] == task_id:
            task['status'] = 'Completed'
            self.save_tasks()
            print(f"Task completed: {task['content']}")
            return
    print("Task not found")


def save_tasks(self):
    with open('tasks.txt', 'w', encoding='utf-8') as f:
        for task in self.tasks:
            f.write(f"{task['content']}|{task['status']}\n")

These codes form the core framework of our task manager, with each line working towards achieving specific functionalities.

Part Three: Bringing the Application to Life – Creating a User-Friendly Interaction Experience

With the core functions in place, let’s inject some soul into this application to make it more user-friendly.

Create a friendly user interface:

def run_app(self):
    print("Welcome to the Personal To-Do List Manager!")
    print("=" * 40)

    while True:
        print("\nPlease choose an operation:")
        print("1. View tasks")
        print("2. Add task")
        print("3. Complete task")
        print("4. Exit program")

        choice = input("\nPlease enter the option number:")

        if choice == '1':
            self.show_tasks()
        elif choice == '2':
            task_content = input("Please enter task content:")
            self.add_task(task_content)
        elif choice == '3':
            self.show_tasks()
            try:
                task_id = int(input("Please enter the task number to complete:"))
                self.complete_task(task_id)
            except ValueError:
                print("Please enter a valid task number")
        elif choice == '4':
            print("Goodbye! Looking forward to your next use")
            break
        else:
            print("Please enter a valid option")

# Start the application

if __name__ == "__main__":
    app = TaskManager()
    app.run_app()

This interaction design reflects three major highlights:

The operation flow is natural and smooth, aligning with user habits.

Error handling is thoughtful and thorough, preventing program crashes.

The interface layout is clear and straightforward, with information easily visible.

Now, when you run this program, you will see a simple and clear interface:

The operation menu is displayed immediately upon opening the program.

Tasks are saved in real-time, so you don’t have to worry about unexpected closures.

Tasks can be marked as completed with one click, providing a sense of achievement.

After exiting and reopening, data is fully retained.

Completing this project from scratch will yield far more than just a tool:

You will prove that code can be so close to life.

You will discover that getting started with programming is not as difficult as you imagined.

You will gain the technical confidence to continue exploring.

Remember these three key takeaways:

Code is not a cold symbol, but an extension of ideas.

Programming is not a profound magic, but a logical expression.

Creation is not a privilege of experts, but a right for everyone.

Now, open your code editor, copy the code above, and run your first homemade application. When you see your program managing tasks effectively, the sense of accomplishment will make you fall in love with programming.

This is not just a to-do list application; it is the key to opening the door to programming. From today, let code be your means of expressing creativity and adding color to your world!

Leave a Comment