+ 2
Military Time in Code Coach (help)
I am having trouble finding the bug in this code. It passes 3/5 of the tests. I can’t see the two test that it fails because they are hidden. Any help will be appreciated 😎 t = input() m = "" if " " in t: t = t.replace(" ","") if t[-2:] == "AM": if t[:2] == '12': m = str('00' + t[2:-2]) else: if t[0]== "0": t = t.replace("0","") m = t[:-2] else: if t[:2] == '12': m = t[:-2] elif len(t)< 7: t = "".join(("0",t)) print(str(int(t[:2]) + 12) + t[2:-2]) else: m = str(int(t[:2])+ 12) + t[2:-2] print(m)
3 odpowiedzi
+ 3
h=input().split()
hr=h[0][0:2]
mn=h[0][3:5]
tm=h[1]
def xx(y):
z=y.zfill(2)
return z
def imp(x,w):
a=(xx(x)+":"+xx(w))
return a
if (tm=='AM' and hr!="12") or (tm=='PM' and hr=="12"):
h=hr
elif tm=='AM' and hr=="12":
h="00"
elif tm=='PM' and hr!="12":
h=str(int(hr)+12)
print(imp(h,mn))
+ 2
Try this:
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]!='
+ 1
Easiest enough with datetime module
https://code.sololearn.com/c0zDUksGAAYs/?ref=app