CBSE Class 12 Computer Science
Question 105 of 105
Python Revision Tour — Question 11
Back to all questions 11
Question Write a program that reads two times in military format (0900, 1730) and prints the number of hours and minutes between the two times.
A sample run is being given below :
Please enter the first time : 0900
Please enter the second time : 1730
8 hours 30 minutes
ft = input("Please enter the first time : ")
st = input("Please enter the second time : ")
# Converts both times to minutes
fMins = int(ft[:2]) * 60 + int(ft[2:])
sMins = int(st[:2]) * 60 + int(st[2:])
# Subtract the minutes, this will give
# the time duration between the two times
diff = sMins - fMins;
# Convert the difference to hours & mins
hrs = diff // 60
mins = diff % 60
print(hrs, "hours", mins, "minutes")Please enter the first time : 0900
Please enter the second time : 1730
8 hours 30 minutes
Please enter the first time : 0915
Please enter the second time : 1005
0 hours 50 minutes