Python: I need to write a program that takes two inputs of military time
(0900,1700)
Python: I need to write a program that takes two inputs of military time
(0900,1700) and output the numbers in hours, minutes
ex: print("Enter the first time:") 0900
print("Enter the second time:") 1700
output 8 hours 30 minutes
And in the reverse order
print("Enter the second time:") 1700
print("Enter the first time:") 0900
output 15 hours 30 minutes
I have tried this and the output was just my input. import datetime,time
first = input("Enter the first time in military hours:") second = input(
"Enter the second time in military hours:")
first_t= datetime.time(hour=int(first[0:2]), minute=int(first[2:4]))
second_t= datetime.time(hour=int(second[0:2]), minute=int(second[2:4]))
hour = ( second.hour-first.hour )
minute= (second.hour-first.hour)
fmt = ("%H ,%M")
print (first_t.strftime(fmt) , second_t.strftime(fmt))
No comments:
Post a Comment