forked from psounis/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomparison3.py
More file actions
54 lines (47 loc) · 1.61 KB
/
Copy pathcomparison3.py
File metadata and controls
54 lines (47 loc) · 1.61 KB
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
49
50
51
52
53
54
class Time:
def __init__(self, hour, minute, second):
self.hour = hour
self.minute = minute
self.second = second
def __str__(self):
return f"{str(self.hour).zfill(2)}:" \
f"{str(self.minute).zfill(2)}:" \
f"{str(self.second).zfill(2)}"
def __gt__(self, other):
if self.hour > other.hour:
return True
elif self.hour == other.hour:
if self.minute > other.minute:
return True
elif self.minute == other.minute:
if self.second > other.second:
return True
return False
def __ge__(self, other):
if self.hour > other.hour:
return True
elif self.hour == other.hour:
if self.minute > other.minute:
return True
elif self.minute == other.minute:
if self.second >= other.second:
return True
return False
def __eq__(self, other):
if isinstance(other, Time):
if self.hour == other.hour and self.minute == other.minute and self.second == other.second:
return True
return False
elif isinstance(other, int):
return self == Time(other, 0, 0)
t = Time(11,1,2)
t2 = Time(11,1,1)
print(f"{t} > {t2}: {t>t2}")
print(f"{t} < {t2}: {t<t2}")
print(f"{t} >= {t2}: {t>=t2}")
print(f"{t} <= {t2}: {t<=t2}")
print(f"{t} == {t2}: {t==t2}")
print(f"{t} != {t2}: {t!=t2}")
t = Time(2,0,0)
print(f"{t} == {2}: {t==2}")
print(f"{2} == {t}: {2==t}")