+ 1

What is wrong with this code? Code coach challange,. Military time challange

It is a military time challange. This code gives first 2 test cases correct and other as failed. import datetime def timeconvert(str1): if str1[-2:]== "AM" and str1[:2] =="12": return "00" + str1[2:-2] elif str1[-2:] == "AM": return str1[:-2] elif str1[-2:]== "PM" and str1[:2]=="12": return str1[:-2] else: return str(int(str1[0:2])+12)+str1[2:5] da=input() print(timeconvert(da)) https://code.sololearn.com/cA9l3sj0Bi3V/?ref=app https://code.sololearn.com/cA9l3sj0Bi3V/?ref=app

17th Mar 2020, 12:34 PM
AKSHAT AGRAWAL
AKSHAT AGRAWAL - avatar
2 odpowiedzi
+ 1
Thank you Dennis i got it🙂
20th Mar 2020, 6:03 PM
AKSHAT AGRAWAL
AKSHAT AGRAWAL - avatar
0
The output should be in XX:XX format. Your code does not follow this rule. For example, your code prints "5:00", whose format is X:XX, for the input "5:00 AM" to get it correct it should be "05:00".
17th Mar 2020, 1:29 PM
Dennis
Dennis - avatar