Answer:
from datetime import time, datetime, timedelta, date
for _ in iter(list, 0):
t1 = input("Please enter time one: ")
t2 = input("Please enter time two: ")
if t1.isdigit() == True and (int(t1[:2])<=23 and int(t1[2:]) <= 59)\
and t2.isdigit() == True and (int(t2[:2])<= 23 and int(t2[2:])<=59):
time_1 = time(hour=int(t1[:2]), minute=int(t1[2:]))
time_2 = time(hour= int(t2[:2]), minute=int(t2[2:]))
if time_1 > time_2:
diff = datetime. combine (date. today( ), time_1) - datetime. combine(date. today ( ), time_2)
else:
diff = datetime. combine (date. today( ), time_2) -datetime. combine(date. today ( ), time_1)
diff_list = str(diff).split(":")
del diff_list[2]
diff_t = "". join (diff_list)
print(diff_t)
break
if t1.isdigit() == False or t2.isdigit() == False:
print("Military Time Forest Required: Bad input, try again.")
continue
elif int(t1[:2])> 23 or int(t2[:2])> 23:
print("Military Tine Format Required: Hours must be between 00 and 23, try again")
continue
elif int(t1[2:])> 59 or int(t2[2:])> 59:
print("Military Tine Format Required: Minutes must be between me and 59, try again")
continue
Explanation:
The python Datetime package is used to manipulate date and time, creating immutable Datetime objects from the various python data types like integer and string. The block of code above is a conditional for-loop statement that gets two user time value inputs and prints out the difference as a string in Military forest time format.