0
Code Coach Military Time
Ques:Change the 12 hour clock to 24 hour clock system Input: 6:32 PM Output: 18:32 n=input().split() x=n[0].index(':') if(n[1]=='PM'): n[0]=str(int(n[0][:x])+12)+n[0][x:x+3] print(n[0]) I have tested this code with various of inputs and all of them came out correct but in the code coach it fails 2 hidden tests idk what the problem is
4 Antworten
+ 5
I quickly tested your code and found 2 things you may wish to address.
12:30 AM should return 00:30
1:30 AM should return 01:30
This challenge highlights the need to fully understand a concept before being able to code the requirements.
You might want to research a bit about military time, so you can catch all the variances.
Hope this helps
+ 1
Thanks i didnt think about that
+ 1
you are using python so ‘datetime,
& strptime’ will be the best for this Code Coach
0
Here is c# code to answer this question first you need know its am or pm if its am you need just hour:minute without modify but if its pm add 12 to hour and you must know that you need to show hour and minute in two digit like 2:3 pm 》 14:03
string clock=Console.ReadLine();
char[] partSign={':',' '};
var sep=clock.Split(partSign);
int hour=Convert.ToInt32(sep[0]);
int minute=Convert.ToInt32(sep[1]);
string am_pm =sep[2];
if(am_pm =="PM")
{
hour+=12;
}
Console.Write(hour.ToString("00")+":"+minute.ToString("00"));