-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.py
More file actions
27 lines (20 loc) · 873 Bytes
/
clock.py
File metadata and controls
27 lines (20 loc) · 873 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
class Clock(object):
def __init__(self, hour, minute):
hour+=minute//60
self.minute=minute%60
self.hour=hour%24
def __repr__(self):
if len(str(self.hour))==1 and len(str(self.minute))==1:
return '0'+str(self.hour)+':'+'0'+str(self.minute)
elif len(str(self.hour))==1 and len(str(self.minute))==2:
return '0'+str(self.hour)+':'+str(self.minute)
elif len(str(self.hour))==2 and len(str(self.minute))==1:
return str(self.hour)+':'+'0'+str(self.minute)
else:
return str(self.hour)+':'+str(self.minute)
def __eq__(self, other):
return self.minute== other.minute and other.hour==self.hour
def __add__(self, minutes):
return Clock(self.hour,self.minute+minutes)
def __sub__(self, minutes):
return Clock(self.hour,self.minute-minutes)