At Westonci.ca, we connect you with experts who provide detailed answers to your most pressing questions. Start exploring now! Join our Q&A platform and get accurate answers to all your questions from professionals across multiple disciplines. Explore comprehensive solutions to your questions from a wide range of professionals on our user-friendly platform.
Sagot :
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.
Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Westonci.ca is committed to providing accurate answers. Come back soon for more trustworthy information.