0

Military time challenge fail in this simple code how?

how this could fail if it’s work perfect on my pc I already tested with 12:00 AM, 12:00 PM, 12:00 am, 12:00 pm, 1:00 AM, 1:00 PM PLEASE tested your self time_normal = input() time_normal = time_normal.split() clock_time = time_normal[0].split(":") time_normal[1] = time_normal[1].upper() if time_normal[1] == "PM": if clock_time[0] != "12": clock_mili = int(clock_time[0]) + 12 clock_time[0] = str(clock_mili) else: if clock_time[0] == "12": clock_time[0] == "00" else: if int(clock_time[0]) < 10 and len(clock_time[0]) == 1: clock_time[0] == "0" + clock_time[0] output = clock_time[0] + ":" + clock_time[1] print(output)

22nd May 2020, 11:34 AM
Oliver Reyes
Oliver Reyes - avatar
8 odpowiedzi
+ 2
Oliver Reyes you can use steing formating to write 00-12. old syntax was print( "%02d:%02d" % (clock_time[0],clock_time[1])) like in C++ . But now there is a new variant with using {} brackets instead of % sign in string formating
23rd May 2020, 9:27 PM
george
george - avatar
+ 1
It sholud output 12:00 AM to 00:00 1:00 AM to 01:00 (single digit 0 to 00, 9 to 09)
22nd May 2020, 12:22 PM
Jayakrishna 🇮🇳
+ 1
Are you getting the those results..? I tested it failing... What you getting for 1:00 AM & 12:00 AM?
22nd May 2020, 12:37 PM
Jayakrishna 🇮🇳
0
it does
22nd May 2020, 12:32 PM
Oliver Reyes
Oliver Reyes - avatar
0
got it: put double equal insted of = in the two else lines that’s the reason in my computer does work
22nd May 2020, 1:17 PM
Oliver Reyes
Oliver Reyes - avatar
0
Yes. Also else part's case 12 code part, also sholud be added in 12 PM case in first if...
22nd May 2020, 1:20 PM
Jayakrishna 🇮🇳
0
thank’s dude is my first lenguage
22nd May 2020, 1:24 PM
Oliver Reyes
Oliver Reyes - avatar
0
oliver reyes You're welcome... Happy learning..
22nd May 2020, 1:57 PM
Jayakrishna 🇮🇳