forked from iamshubhamg/Leet-Code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimedifference.py
More file actions
29 lines (29 loc) · 742 Bytes
/
timedifference.py
File metadata and controls
29 lines (29 loc) · 742 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
27
28
29
import datetime
from fractions import Fraction
ss=[int(i) for i in input().split(":")][:3]
h, m, s = ss
a = datetime.datetime(1, 1, 1, h, m, s)
ss=[int(i) for i in input().split(":")][:3]
h, m, s = ss
b = datetime.datetime(1, 1, 1, h, m, s)
ss=input()
c = abs(a-b)
c = c.seconds
if ss.casefold()=="h":
if c//3600==0 and c!=0:
print("1",end=" ")
else:
print(c//3600,end=" ")
if Fraction(c%3600, 3600)!=0:
print(Fraction(c%3600, 3600),end=" ")
print("Hours")
elif ss.casefold()=="m":
if c//60==0 and c!=0:
print("1",end=" ")
else:
print(c//60,end=" ")
if Fraction(c%60, 60)!=0:
print(Fraction(c%60, 60),end=" ")
print("Minutes")
else:
print(c,"Seconds")