+ 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

18th Jun 2020, 9:14 PM
Randy Ziegler
Randy Ziegler - avatar
14 Antworten
20th Jun 2020, 4:00 AM
Jonathan Alvarado
Jonathan Alvarado - avatar
+ 4
using what Russ said output for 12:45 PM is 12:45 instead of 24:45 ,so how outputs are same?
18th Jun 2020, 11:08 PM
Abhay
Abhay - avatar
+ 1
mil_convert=(int(civ_time[:-6])%12)+12 maybe?
18th Jun 2020, 9:52 PM
Russ
Russ - avatar
+ 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)
19th Jun 2020, 3:23 PM
Russ
Russ - avatar
+ 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.
19th Jun 2020, 4:25 PM
Russ
Russ - avatar
0
nope, same outputs
18th Jun 2020, 10:37 PM
Randy Ziegler
Randy Ziegler - avatar
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
19th Jun 2020, 12:48 AM
Randy Ziegler
Randy Ziegler - avatar
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?
19th Jun 2020, 1:00 AM
Randy Ziegler
Randy Ziegler - avatar
0
Pls send help lol
19th Jun 2020, 2:15 PM
Randy Ziegler
Randy Ziegler - avatar
0
Based on this, I'm thinking just scrap it and start over lol
19th Jun 2020, 2:16 PM
Randy Ziegler
Randy Ziegler - avatar
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
19th Jun 2020, 4:06 PM
Randy Ziegler
Randy Ziegler - avatar
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
19th Jun 2020, 5:09 PM
Randy Ziegler
Randy Ziegler - avatar
0
so that 12:30 AM becomes 00:30
19th Jun 2020, 5:09 PM
Randy Ziegler
Randy Ziegler - avatar
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
20th Jun 2020, 3:01 PM
Randy Ziegler
Randy Ziegler - avatar