Course Capstone Mini-Project

The Capstone Challenge

Welcome to the Finish Line!

It's time to combine everything you've learned to build a Command-Line Task Manager. This application will allow users to manage their daily to-do list directly from the terminal.

You will utilize:

Congratulations on reaching the final lesson! Today, you aren't just learning a syntax; you are building a real-world tool: a Command-Line Task Manager. We will use this project to synthesize variables, loops, functions, and dictionaries into one working script.

Mapping Your Data

Why a Dictionary?

We need a way to store tasks where each task has a unique ID. A dictionary is perfect for this because we can use the ID as the key and the task description as the value.

tasks = {
  1: "Buy groceries",
  2: "Finish Python project"
}

Before we write functions, we need a place to keep our data. We will use a dictionary called 'tasks'. The key will be a unique ID number, and the value will be the task description. This setup makes finding and deleting tasks incredibly efficient.

Modular Design: Core Functions

Defining the Logic

A good programmer breaks their code into functions. This makes the code modular and easier to test.

To keep our script clean, we will define core functions. The 'add_task' function will take a description and put it in our dictionary. The 'view_tasks' function will loop through our dictionary to show the user what they have to do.

Handling Errors Gracefully

The try...except Block

When a user types a letter instead of a number for a Task ID, Python will normally throw a ValueError and crash. We use try...except to prevent this.

Users don't always do what we expect. If they type a word when we expect a number, the program crashes. By wrapping our input in a try...except block, we can catch that error and give them a second chance without the script stopping. Excellent! Now, even if the input is bad, the program stays running and asks the user to try again.

The Main Program Loop

The User Interface

A command-line app needs to stay open until the user is done. We use a while True loop to create an infinite menu that only stops when the user selects 'Exit'.

while True:
    print("1. Add Task")
    # ... get input ...
    if choice == '4':
        break

The heart of our application is the main loop. This 'while True' loop keeps the menu appearing after every action. We only leave this loop when the user chooses the 'Exit' option, which triggers the 'break' keyword.

Code the 'View Tasks' Logic

Writing Exercise

Write a brief logic description or code snippet that would loop through a dictionary called tasks and print each task_id and description.

Now it's your turn. How would you display the tasks stored in our dictionary? Write a short explanation or the Python loop you'd use to print every task ID and its description.

Common Pitfalls to Avoid

Watch Your Step!

Even experienced developers run into these issues:

As you build your project, keep an eye out for these common traps. A KeyError happens if you try to delete a task ID that isn't there. And remember, a variable created inside a function stays inside that function unless you explicitly return it.

The Freelancer's Assistant

Final Role-Play

Imagine you are the developer. A freelancer (AI) wants to add a few tasks and then see their list. Practice interacting with the 'user' to see if your logic holds up.

Let's test your understanding of the app's flow. Meet Alex, a freelancer. Alex will ask you how to perform certain actions in your new app. Explain the process clearly.

Course Complete!

You Did It!

You have successfully navigated the foundations of Python. From variables to building a full Command-Line Application, you now have the tools to start creating your own software.

Next Steps:

You've done it! You've gone from 'Hello World' to building a functional, error-resistant application. The world of programming is vast, but you now have a rock-solid foundation. Keep coding, keep building, and most importantly—keep curious!