I am currently working on a program regarding clock arithmetic. My program asks the user for two separate times, in standard format and in military time [HH:MM:SS]. I then add those two times together to get my final result. I need help with two issues that I have tried to solve, but I have struggled a lot with.
In the end, it is supposed to look like this: HH:MM:SS + HH:MM:SS = HH:MM:SS The result all depends on what the user inputs
Would you be able to tell me a way I can prevent the time from going to/over 24 hours, 60 minutes, and 60 seconds? These are the cut-offs and a summed time would not make sense if the hours, minutes, or seconds went past their cut-offs. I wanted to know how I could do this, I was thinking that it would take integer division or modulus operators (%). I would greatly appreciate your help here. I need to keep my time within these boundaries because the user could pick any time that could spill over. After these cut-offs have been reached, the time should restart back to zero and wrap around from there.
How do I ensure that my final time stays in [HH:MM:SS] format? I would greatly appreciate your help with this. Some of the time, the format is coming out as [H:M:S], which is what I do not want.
I would greatly appreciate your help with these two issues that I am struggling with. I am so close to having everything down right. I just need to know the code for giving my time a cut-off to restart after reaching a certain limit, as well as a way to keep the [HH:MM:SS] format in place. My code for the program is listed below. Thank You so much,
Code
ClockTime1 = input('Enter clock two timie (in military time) in
the format HH:MM:SS , it has to be in this format in order to
function correctly :')
ClockTime2= input('Enter clock one time (in military time) in
the format HH:MM:SS , it has to be in this format in order to
function correctly :')
print(ClockTime1.split(':'))
print(ClockTime2.split(':'))
ClockTime1Hours= int((ClockTime1.split(':')[0]))
ClockTime2Hours= int((ClockTime2.split(':')[0]))
ClockTime2Minutes= int((ClockTime2.split(':')[1]))
ClockTime1Seconds= int((ClockTime1.split(':')[2]))
ClockTime2Seconds= int((ClockTime2.split(':')[2]))
print(ClockTime1Hours,'hours for clock 1')
print(ClockTime2Hours,'hours for clock 2')
print(ClockTime1Minutes,'minutes for clock 1')
print(ClockTime2Minutes,'minutes for clock 2')
print(ClockTime1Seconds,'seconds for clock 1')
print(ClockTime2Seconds,'seconds for clock 2')
ClockTime1Hours += ClockTime2Hours
print('sum of clock hours=',ClockTime1Hours)
ClockTime1Minutes += ClockTime2Minutes
print('sum of clock minutes=',ClockTime1Minutes)
ClockTime1Seconds += ClockTime2Seconds
print('sum of clock seconds=',ClockTime1Seconds)
What the console shows:
Enter clock two time (in military time) in the format HH:MM:SS
, it has to be in this format in order to function correctly
:2:00:00
Enter clock one time (in military time) in the format HH:MM:SS
, it has to be in this format in order to function correctly
:3:00:00
['2', '00', '00']
['3', '00', '00']
2 hours for clock 1
3 hours for clock 2
0 minutes for clock 1
0 minutes for clock 2
0 seconds for clock 1
0 seconds for clock 2
sum of clock hours= 5
sum of clock minutes= 0
sum of clock seconds= 0
Sum of Times=5:0:0