Military time code coach solution | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Military time code coach solution

****** Actually Question. You want to convert the time from a 12 hour clock to a 24 hour clock. If you are given the time on a 12 hour clock, you should output the time as it would appear on a 24 hour clock. Task: Determine if the time you are given is AM or PM, then convert that value to the way that it would appear on a 24 hour clock. Input Format: A string that includes the time, then a space and the indicator for AM or PM. Output Format: A string that includes the time in a 24 hour format (XX:XX) Sample Input: 1:15 PM Sample Output: 13:15. ********* I passed 4 out of 5 test cases 😐. What's wrong with my code? https://code.sololearn.com/czHpkv92bK4T/?ref=app

30th Mar 2022, 1:21 PM
David Holmes Ng'andu
David Holmes Ng'andu - avatar
5 Answers
+ 2
12:34 AM output need is 00:34 But getting 12:34 12:34 PM output need is 12:34 But getting 00:34 Reverse it. hope it helps....
30th Mar 2022, 1:24 PM
Jayakrishna 🇮🇳
+ 2
@David Holmes Ng'andu is this code is only sample for testing? As you said only one case failing, not tested fully.. but for input of single digit hour, print in double digit like : 7:54 AM => 07:54
30th Mar 2022, 4:08 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 i fixed that and it now says the correct thing but i still fail one more case. Check my new code
30th Mar 2022, 6:29 PM
David Holmes Ng'andu
David Holmes Ng'andu - avatar
0
David Holmes Ng'andu Only one, ..? As I already told, it failing when input hour is single digit 1:45 AM => 01:45 but output is 1:45 means append 0 is needed
30th Mar 2022, 6:51 PM
Jayakrishna 🇮🇳