Code coach failed 2/5 test cases but works on interpreter? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Code coach failed 2/5 test cases but works on interpreter?

The code coach problem: Convert 12 hour time to 24 hour time. Assume input is a string formatted `XX:XX (AM or PM)’ Example input 1:34 PM Example output 13:34 My code is as follows: def clock(n): time = n.split(':') hours = time[0] minutes = time[1].split() ampm = minutes[1] minutes = minutes[0] if ampm == 'AM': if hours == '12': hours = '00' elif ampm == 'PM': if hours == '12': hours = '12' else: hours = str(int(hours) + 12) time = hours + ':' + minutes return time print(clock(input())) I’ve run it on every possible combination I can on Interpreter with no issues. I’m a beginner but I can’t for the life of me figure out why? Version difference? Missed parameter? Can anyone help?

6th Mar 2020, 9:28 PM
Cade
Cade - avatar
5 Answers
+ 4
Your problem is the output format: XX:XX For example: 03:12 instead of 3:12
6th Mar 2020, 10:02 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
I think, It missing 1 to 11 AM, and should be same as it is like 1:00 AM is 01:00, and 11:00 AM as 11:00
6th Mar 2020, 10:53 PM
Jayakrishna 🇮🇳
0
I didnt consider that the input would follow that format. I assumed 1:30 as input not 01:30. Makes perfect sense thank you!
6th Mar 2020, 10:06 PM
Cade
Cade - avatar
0
Denise Roßberg I added this, but still failed the same two tests if hours[0] == 0 and hours[1] != 0: hours = hours[1]
6th Mar 2020, 10:25 PM
Cade
Cade - avatar
0
oops forgot Denise Roßberg
6th Mar 2020, 10:25 PM
Cade
Cade - avatar