-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskManager.py
More file actions
46 lines (40 loc) · 1.29 KB
/
Copy pathtaskManager.py
File metadata and controls
46 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from task import Task
from typing import List
from datetime import date
class TaskManager:
def __init__(self):
"""
Initializes the TaskManager with an empty list of tasks.
"""
self.tasks: List[Task] = []
def add_task(self, title: str, description: str, due_date: date):
"""
Adds a new task to the task list.
"""
new_task = Task(title, description, due_date)
self.tasks.append(new_task)
def get_pending_tasks(self) -> List[Task]:
"""
Returns a list of tasks that are not yet completed.
"""
not_completed = []
for task in self.tasks:
if not task.completed:
not_completed.append(task)
return not_completed
def get_completed_tasks(self) -> List[Task]:
"""
Returns a list of tasks that are completed.
"""
completed = []
for task in self.tasks:
if task.completed:
completed.append(task)
return completed
def mark_task_completed(self, task_index: int):
"""
Marks a specific task as completed based on its index.
"""
if not task_index < len(self.tasks) or not task_index >= 0:
return
self.tasks[task_index].mark_completed()