+ 4

What is wrong with my code ?

there was this challenge 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 for this the my code can't pass the 3rd and 5th test. can anyone tell the problem ? https://code.sololearn.com/c4qBSXAMsu2n/?ref=app https://code.sololearn.com/c4qBSXAMsu2n/?ref=app

1st Mar 2020, 7:56 AM
Jatin Kumar
Jatin Kumar - avatar
6 Answers
+ 3
by using the basics only ✌ https://code.sololearn.com/cqOgKoFFGw4m/?ref=app
1st Mar 2020, 10:23 AM
Suraj Das
Suraj Das - avatar
0
look at 12am and 12pm also the output format https://code.sololearn.com/c35kHk5nfTTv/?ref=app
1st Mar 2020, 8:02 AM
Taste
Taste - avatar
0
x=input() lst0=list(x) lst=[] for j in range(0,len(lst0)): if lst0[j].isdigit and lst0[j]!=':' and lst0[j]!=' ' and lst0[j]!="P" and lst0[j]!="A" and lst0[j]!="M": lst+=int(lst0[j]), elif lst0[j]==":" and lst0[j]!=' ': lst+=lst0[j], elif lst0[j]==' ': lst+=lst0[j], elif lst0[j]=="P": lst+=lst0[j], elif lst0[j]=="A": lst+=lst0[j], elif lst0[j]=="M": lst+=lst0[j], if lst[1]!=':' and "P" in lst: if lst[0]==1 and lst[1]<=1 and "P" in lst: lst[0]+=1 lst[1]+=2 lst[5]="" lst[6]="" lst[7]="" elif lst[0]==1 and lst[1]==2 and "P" in lst: lst[5]="" lst[6]="" lst[7]="" elif lst[0]==1 and lst[1]==2 and "P" in lst: lst[5]="" lst[6]="" lst[7]="" elif lst[1]==':' and "P" in lst: if lst[0]<=9 and "P" in lst: lst[0]+=12 lst[4]="" lst[5]="" lst[6]="" elif lst[1]!=':' and "A"
11th May 2020, 3:05 PM
Akshay S Kumar
Akshay S Kumar - avatar
0
#Swift #swift import Foundation var myString = readLine() ?? ")" var result = myString.components(separatedBy: " ") if result[1] == "AM"{ print(result[0]) }else{ var s = result[0].components(separatedBy: ":") s.insert(String(Int(s.first!)! + 12), at: 0) s.removeLast() var final = s.joined(separator: ":") print(final) }
11th Oct 2022, 9:58 AM
Artem Leschenko
Artem Leschenko - avatar
0
list = input().split(' ') time = list[0] o = list[1] s = [13,14,15,16,17,18,19,20,21,22,23] if o == 'AM': print(time) elif o == 'PM': n = time.split(':') y = s [int(n[0])-1] p = str(y) + ':' + str(n[1]) print(p)
30th Jan 2023, 5:55 PM
Ruzik73
0
x = input() if "PM" in x: k = int(x[:2]) x = str(k + 12) + str(x[2:-3]) else: x = x[:-3] print(x)
8th Jun 2023, 6:17 PM
Krzysztof Ryczkowski
Krzysztof Ryczkowski - avatar