DEV Community

Cover image for Simple Command-Line Task Manager in Python.
Lawani Elyon John
Lawani Elyon John

Posted on β€’ Edited on

1

Simple Command-Line Task Manager in Python.


Table of Contents

  1. πŸ› οΈ Setting up the Development Environment
  2. πŸ“‹ Prerequisites
  3. πŸš€ Project Initialization
  4. 🧩 Implementing Features
  5. πŸ› Testing and Debugging
  6. 🏁 Final Project

In this tutorial, we’ll build a command-line task manager using Python. Task managers are great for learning programming basics like user input, loops, conditionals, and lists. By the end, you'll have a working task manager where you can add, view, update, and delete tasks.

Setting up the Development Environment πŸ–₯️

Choosing a programming language is crucial. Python is versatile for web development, software, math, and system scripting. To start, make sure you have Python installed. Download Python.

Python Development

  1. Install an IDE: We’ll use Visual Studio Code for code writing, debugging, and compiling. Download VS Code.

VS Code

Project Initialization πŸš€

With everything set up, create a directory and a Python file:

mkdir task_manager
cd task_manager
touch task_manager.py
Enter fullscreen mode Exit fullscreen mode

This will be your main file where the task management logic goes.

Implementing the Features ✨

Adding Tasks βž•

Here’s a function to add tasks:

tasks = []

def create_tasks():
    title = input("Enter Your Task Title: ")
    description = input("Enter Your Task Description: ")
    tasks.append({"Task Title": title, "Task Description": description})
    print("βœ… Task Created Successfully.")
Enter fullscreen mode Exit fullscreen mode

This function prompts the user for a task title and description, then adds it to the task list.

Main Menu πŸ—‚οΈ

Create an interactive loop for user options:

while True:
    print("\nWelcome to the Interactive Task Manager")
    print("1. Add Task")
    print("2. View Task")
    print("3. Update Task")
    print("4. Delete Task")
    print("5. Exit")

    choice = input("Select an option from (1-5): ")

    if choice == '1':
        create_tasks()
    elif choice == '2':
        see_tasks()
    elif choice == '3':
        update_tasks()
    elif choice == '4':
        delete_tasks()
    elif choice == '5':
        print("Exiting the task manager.")
        break
    else:
        print("⚠️ Invalid option. Please select between 1 and 5.")
Enter fullscreen mode Exit fullscreen mode

Viewing Tasks πŸ‘€

To view created tasks:

def see_tasks():
    if tasks:
        print("Available Tasks:")
        for idx, task in enumerate(tasks, start=1):
            print(f"{idx}. Task Title: {task['Task Title']}, Task Description: {task['Task Description']}")
    else:
        print("πŸ“­ No Tasks Available.")
Enter fullscreen mode Exit fullscreen mode

Updating Tasks ✏️

The update_tasks() function enables flexible task updating:

def update_tasks():
    see_tasks()
    if tasks:
        tasks_index = int(input("Provide the Index of your task to be updated: ")) - 1
        if 0 <= tasks_index < len(tasks):
            new_task_title = input("Provide your new title or (Press Enter to keep current title): ")
            new_task_description = input("Provide your new description or (Press Enter to keep current description): ")
            if new_task_title: ""
                tasks[tasks_index]['Task Title'] = new_task_title
            if new_task_description: ""
                tasks[tasks_index]['Task Description'] = new_task_description
            print("βœ… Task Updated")
        else:
            print("⚠️ Invalid Index.")
    else:
        print("πŸ“­ No Tasks Available.")
Enter fullscreen mode Exit fullscreen mode

Deleting Tasks πŸ—‘οΈ

To remove unwanted tasks:

def delete_tasks():
    see_tasks()
    if tasks:
        tasks_index = int(input("Provide the Index of the task to be deleted: ")) - 1
        if 0 <= tasks_index < len(tasks):
            deleted_task = tasks.pop(tasks_index)
            print(f"πŸ—‘οΈ Task '{deleted_task['Task Title']}' deleted successfully.")
        else:
            print("⚠️ Invalid Index.")
    else:
        print("πŸ“­ No Tasks Available.")
Enter fullscreen mode Exit fullscreen mode

Testing and Debugging πŸ”

  1. Testing the Add Function: Check if tasks are stored and displayed.
  2. Testing the Update Function: Ensure title or description updates work independently.
  3. Testing the Delete Function: Try deleting tasks and see if the list updates correctly.
  4. Edge Cases: Test program behavior with no tasks, invalid inputs, etc.

Output πŸŽ‰

Task Manager Output

Conclusion πŸ†

You’ve built a simple task manager using Python! You learned:

  • Setting up a development environment
  • Task management features like add, view, update, delete
  • Testing and debugging techniques

Future Extensions πŸš€

  1. Add file-saving for persistence.
  2. Add due dates for tasks.
  3. Create categories for task organization.

Acknowledgments πŸ™Œ

Special thanks to codingdidi for inspiration. Check out the helpful YouTube video here: YouTube Tutorial.


Neon image

Build better on Postgres with AI-Assisted Development Practices

Compare top AI coding tools like Cursor and Windsurf with Neon's database integration. Generate synthetic data and manage databases with natural language.

Read more β†’

Top comments (0)

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment JosΓ© and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay