Skip to content

Commit f05dc15

Browse files
committed
Finished working on the clock challenge
1 parent 0d94cf0 commit f05dc15

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed
1.01 KB
Binary file not shown.
11.7 KB
Binary file not shown.

clock/clock.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
class Clock:
1+
#11/23/2019 - I suffered from overthinking here, did a deepdive into time and datetime python libraries instead of just doing basic math.
2+
3+
class Clock(object):
24
def __init__(self, hour, minute):
3-
pass
5+
self.hour = (hour + minute // 60) % 24
6+
self.minute = minute % 60
47

58
def __repr__(self):
6-
pass
9+
return "{:02d}:{:02d}".format(self.hour, self.minute)
710

811
def __eq__(self, other):
9-
pass
12+
return str(self) == str(other)
1013

1114
def __add__(self, minutes):
12-
pass
15+
return Clock(self.hour, self.minute + minutes)
1316

1417
def __sub__(self, minutes):
15-
pass
18+
return Clock(self.hour, self.minute - minutes)

0 commit comments

Comments
 (0)