Skip to content

Commit 3bf71b9

Browse files
committed
#25-Python
1 parent cc9df18 commit 3bf71b9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Logs
2+
import logging
3+
import time
4+
5+
logging.basicConfig() # By default warning level
6+
7+
8+
def print_logs():
9+
logging.debug("This is a debug level log")
10+
logging.info("This is a info level log")
11+
logging.warning("This is a warning level log")
12+
logging.error("This is a error level log")
13+
logging.critical("This is a critical level log")
14+
15+
print_logs()
16+
17+
logging.getLogger().setLevel(logging.DEBUG)
18+
print_logs()
19+
20+
# EXTRA
21+
22+
class TaskManager:
23+
24+
def __init__(self):
25+
self.tasks = {}
26+
27+
def add_task(self, name, description):
28+
start = time.time()
29+
if name not in self.tasks:
30+
logging.info(f"adding task {name}")
31+
self.tasks[name] = description
32+
else:
33+
logging.error(f"task {name} already exists")
34+
end = time.time()
35+
logging.debug(f"adding task time {end-start}s")
36+
37+
def remove_tasks(self, name):
38+
start = time.time()
39+
if name in self.tasks:
40+
logging.info(f"removing task {name}")
41+
self.tasks.pop(name)
42+
else:
43+
logging.error(f"task {name} not found")
44+
end = time.time()
45+
logging.debug(f"removing task time {end-start}s")
46+
47+
def list_tasks(self):
48+
start = time.time()
49+
for key, value in self.tasks.items():
50+
print(f"Task: {key}. Description: {value}")
51+
end = time.time()
52+
logging.debug(f"listing task time {end-start}s")
53+
54+
55+
task_manager = TaskManager()
56+
task_manager.add_task("SW Acolyte", "New episode wednesday")
57+
task_manager.add_task("Do house", "Clean")
58+
task_manager.list_tasks()
59+
task_manager.remove_tasks("SW Acolyte")
60+
task_manager.list_tasks()
61+
task_manager.add_task("Acolyte", "Create review")
62+
task_manager.remove_tasks("Do house")

0 commit comments

Comments
 (0)