Python 编程:我需要编写一个程序,需要两个输入的军事时间。例如,(0900,1700) 并以小时、分钟为单位输出两个输入的时间差
前任:
print("Enter the first time:") 0900
print("Enter the second time:") 1730
输出
8 hours 30 minutes
并以相反的顺序
print("Enter the second time:") 1730
print("Enter the first time:") 0900
输出
15 hours 30 minutes
我试过下面的代码,但输出只是我的输入。
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))
对于输入值0500,1830
,它给了我输出05 , 00 18 , 30