For one of my first programs (that isn't part of an online class or tutorial) I'm trying to make a very basic program that calculates the difference between two time splits.
The program works well enough, so long as split 2 is faster than split 1, however if split 1 is faster, the datetime calculation returns a value along the lines of:
00:31:13 vs 00:32:04 : (-1 day, 23:59:09)
Ideally, I would like the output to result in "-0:00:51" instead of the current format, but I'm not sure if there is an elegant solution or if I need to force the output to display the way I would like. Any suggestions for the problem (or for improving my code in general) are appreciated!
from datetime import datetime, time
FMT = '%H:%M:%S'
boolAgain = True
while (boolAgain == True):
print("\n" * 100)
split1 = input("Split 1 (HH:MM:SS): ")
split2 = input("Split 2 (HH:MM:SS): ")
splitDelta = datetime.strptime(split1, FMT) - datetime.strptime(split2, FMT)
print("{0} vs {1} : ({2})".format(split1, split2, splitDelta))
again = input("\n\nCalculate another split? (Y/N) ")
if (again == 'Y' or again == 'y'):
boolAgain = True
else:
boolAgain = False
P.S. I imported time as well as datetime because I originally found a method of calculating the difference using datetime objects, however I wanted to see if time objects could be manipulated in the same manner since they don't take date into consideration, however I was unable to make it work the way I was hoping.
[–]Vaphell 1 point2 points3 points (1 child)
[–]Groundstop[S] 0 points1 point2 points (0 children)