+ 2
To fix or to scrap, that is the question... -Shakespeare
I am having some difficulty with the Military Time code coach, my program works beautifully... until you input 12:xx PM. If you input 12:45 PM, the program gives you 24:45 đ is there a relatively simple way to correct this, or should I scrap the whole program and go a different route? NOTE: I AM NOT LOOKING FOR THE EXACT COPY PASTE CODE TO FIX IT, ONLY OPINIONS ON WHETHER OR NOT IT IS FIXABLE IN ITS CURRENT STATE Thank you everyone! https://code.sololearn.com/ctf5hOJk6jiu/?ref=app
14 RĂ©ponses
0
Here is my approach
https://code.sololearn.com/cSJD7rmif6OD/?ref=app
+ 4
using what Russ said output for 12:45 PM is 12:45 instead of 24:45 ,so how outputs are same?
+ 1
mil_convert=(int(civ_time[:-6])%12)+12 maybe?
+ 1
I don't think it needs scrapping. Based on what you said (about 1:45 needing to be 01:45), just address that issue.
if hours < 10:
hours = f"0{hours}"
(or if that notation is unfamiliar)
if hours < 10:
hours = "0" + str(hours)
+ 1
Ok. So hours % 12 will be between 0 and 11 (inclusive). If PM, then simply add 12, right?
And then if hours % 12 < 10, add extra "0" on the front.
0
nope, same outputs
0
I stand corrected, the outputs arent the same, but I'm still getting 2/5 fails. I think I need to account for 0:00 or 00:00
0
my other guess is to try splitting the input into a list of hours, minutes, and am/pm and maybe handling it like that?
0
Pls send help lol
0
Based on this, I'm thinking just scrap it and start over lol
0
no no, the issue (at least i think) is that in military time, 12:00 am=00:00, to differentiate between 12:00 pm, which remains 12:00
0
no, basically what i need (i think) is a way to add a third if/elif that says if hours=12 and civ_time[-2:]=AM, switch the 12 to 00
0
so that 12:30 AM becomes 00:30
0
thanks, I'll have a look tonight and try to incorporate bits into my own code! Also thanks for not explicitly solving it for me, I still wanna learn whats going on rather than recieving copy-paste bits that arent teaching me anything