+ 2

Military Time.!

def convert24(str1): str1 = str1.replace(" ","") 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] elif str1[-2:] == "PM" and str1[0] == "0": return str(int(str1[:2]) + 12) + str1[2:-2] elif str1[-2:] == "PM" and str1[1] == ":": return str(int(str1[:1]) + 12) + str1[1:-2] else : return str(int(str1[:2]) + 12) + str1[2:-2] str1=input() print(convert24(str1)) 3rd and 5th case failed.

21st Apr 2020, 12:40 PM
Kashyap Patel
1 Resposta
+ 1
I've just test your code and if you insert "1:00 AM" the output will be "1:00" and not "01:00"
21st Apr 2020, 12:59 PM
LoCoding
LoCoding - avatar