This repository was archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise-general-week-05-09-answer.py
More file actions
64 lines (50 loc) · 1.66 KB
/
exercise-general-week-05-09-answer.py
File metadata and controls
64 lines (50 loc) · 1.66 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from enum import Enum, auto
import sys
tasks = []
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 2 <-----
class Importance(Enum):
LOW = auto()
MEDIUM = auto()
HIGH = auto()
class Task:
title = None
description = None
is_done = False
importance = None
def __init__(self, title, description, importance=Importance.MEDIUM) -> None:
self.title = title
self.description = description
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 2 <-----
self.importance = importance
def done(self):
self.is_done = True
def __str__(self) -> str:
done = "x" if self.is_done else "-"
return f"[{done}] {self.title.ljust(15)} '{self.description.ljust(30)}', {self.importance.name}"
def __repr__(self) -> str:
return self.__str__()
tasks.append(Task("Buy", "Buy soda for dinner"))
tasks.append(Task("Gym", "Go to gym", importance=Importance.LOW))
tasks.append(Task("Mail", "Send mail to Office", importance=Importance.HIGH))
tasks.append(Task("Wash your Car", ""))
tasks.append(Task("Buy", "Buy a pen"))
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 1 <-----
tasks.append(Task("Buy", "Buy a car"))
tasks.append(Task("Buy", "Buy a phone"))
tasks[1].done()
tasks[2].done()
# for task in tasks:
# print(task)
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 3 <-----
L, c = len(tasks), 0
while c < L:
print(tasks[c])
c += 1
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 4 <-----
with open(sys.path[0]+"/temp.txt","w") as file:
file.write(str(tasks))