Table of Contents
- π οΈ Setting up the Development Environment
- π Prerequisites
- π Project Initialization
- 𧩠Implementing Features
- π Testing and Debugging
- π 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.
- Install an IDE: Weβll use Visual Studio Code for code writing, debugging, and compiling. Download 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
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.")
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.")
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.")
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.")
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.")
Testing and Debugging π
- Testing the Add Function: Check if tasks are stored and displayed.
- Testing the Update Function: Ensure title or description updates work independently.
- Testing the Delete Function: Try deleting tasks and see if the list updates correctly.
- Edge Cases: Test program behavior with no tasks, invalid inputs, etc.
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 π
- Add file-saving for persistence.
- Add due dates for tasks.
- Create categories for task organization.
Acknowledgments π
Special thanks to codingdidi for inspiration. Check out the helpful YouTube video here: YouTube Tutorial.
Top comments (0)