-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.py
48 lines (42 loc) · 1.26 KB
/
timer.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
39
40
41
42
43
44
45
46
47
48
class Timer:
def __init__(self, hours, minutes, seconds):
self.__hours = hours
self.__minutes = minutes
self.__seconds = seconds
def __str__(self):
hour = str(self.__hours).zfill(2)
minute = str(self.__minutes).zfill(2)
second = str(self.__seconds).zfill(2)
return hour + ':' + minute + ':' + second
def next_second(self):
if self.__seconds == 59:
self.__seconds = 0
if self.__minutes == 59:
self.__minutes = 0
if self.__hours == 23:
self.__hours = 0
else:
self.__hours += 1
else:
self.__minutes += 1
else:
self.__seconds += 1
def prev_second(self):
if self.__seconds == 0:
self.__seconds = 59
if self.__minutes == 0:
self.__minutes = 59
if self.__hours == 0:
self.__hours = 23
else:
self.__hours -= 1
else:
self.__minutes -= 1
else:
self.__seconds -= 1
timer = Timer(23, 59, 59)
print(timer)
timer.next_second()
print(timer)
timer.prev_second()
print(timer)