Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

class Task:

def __init__(self, name, description, deadline, priority):


self.name = name
self.description = description
self.deadline = deadline
self.priority = priority
self.completed = False

def __str__(self):
status = "Completed" if self.completed else "Incomplete"
return f"Task: {self.name}\nDescription: {self.description}\nDeadline:
{self.deadline}\nPriority: {self.priority}\nStatus: {status}\n"

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

def add_task(self, task):


self.tasks.append(task)

def remove_task(self, task_name):


for task in self.tasks:
if task.name == task_name:
self.tasks.remove(task)
return
print("Task not found.")

def update_task(self, task_name, updated_description, updated_deadline,


updated_priority, completed=False):
for task in self.tasks:
if task.name == task_name:
task.description = updated_description
task.deadline = updated_deadline
task.priority = updated_priority
task.completed = completed
return
print("Task not found.")

def get_all_tasks(self):
return self.tasks

def get_task_by_name(self, name):


for task in self.tasks:
if task.name == name:
return task
return None

def generate_report(self):
completed_tasks = [task for task in self.tasks if task.completed]
incomplete_tasks = [task for task in self.tasks if not task.completed]

print(f"Completed Tasks ({len(completed_tasks)}):")


for task in completed_tasks:
print(task)

print(f"Incomplete Tasks ({len(incomplete_tasks)}):")


for task in incomplete_tasks:
print(task)
def main():
task_manager = TaskManager()

# Add some tasks to the task manager.


task_manager.add_task(Task("Finish this task manager", "Implement all the
features.", "2023-10-09", 1))
task_manager.add_task(Task("Write a blog post about this task manager",
"Describe the features and benefits of this task manager.", "2023-10-10", 2))

# Update a task.
task_manager.update_task("Finish this task manager", "Implement all the
features and tests.", "2023-10-09", 1, completed=True)

# Remove a task.
task_manager.remove_task("Write a blog post about this task manager")

# Generate a report.
task_manager.generate_report()

if __name__ == "__main__":
main()

You might also like