-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.py
38 lines (33 loc) · 1.01 KB
/
time.py
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
class Timer:
def __init__(self, hours, minutes, seconds):
self.__hours = hours
self.__minutes = minutes
self.__seconds = seconds
def __str__(self):
return f"{self.__hours:02d}:{self.__minutes:02d}:{self.__seconds:02d}"
def next_second(self):
self.__seconds += 1
if self.__seconds == 60:
self.__seconds = 0
self.__minutes += 1
if self.__minutes == 60:
self.__minutes = 0
self.__hours += 1
if self.__hours == 24:
self.__hours = 0
def prev_second(self):
self.__seconds -= 1
if self.__seconds == -1:
self.__seconds = 59
self.__minutes -= 1
if self.__minutes == -1:
self.__minutes = 59
self.__hours -= 1
if self.__hours == -1:
self.__hours = 23
timer = Timer(23, 59, 59)
print(timer)
timer.next_second()
print(timer)
timer.prev_second()
print(timer)