-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmay16exercise2.py
More file actions
29 lines (22 loc) · 863 Bytes
/
may16exercise2.py
File metadata and controls
29 lines (22 loc) · 863 Bytes
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
# Exercise 2
# Create a TodoList class with a tasks list (which will contain instances of the Task class).
# Create an __init__ method and an add_task method that allows you to pass in an instance of your Task class.
# Try creating a todo list and adding your three tasks to it.
from may16exercise1 import *
class TodoList:
def __init__(self, name):
self.name = name
self.tasks_list = []
def __str__(self):
for task in self.tasks_list:
return f'{task.description}, {task.due_date}'
# print(f'{task.description}, {task.due_date}')
def add_task(self, task):
self.tasks_list.append(task)
my_list = TodoList('My Todo List')
my_list.add_task(task1)
my_list.add_task(task2)
my_list.add_task(task3)
print(my_list.tasks_list)
print(my_list)
print(type(f'{task1.description}, {task1.due_date}'))