0
convert 12 hours to 24?
i tried to solve: https://www.sololearn.com/coach/70?ref=app but have problem in case 3 and 5 here iz my code: https://code.sololearn.com/cQNhvJu1KDaT/?ref=app what's the prob?
5 ответов
+ 4
a=input()
b=a.replace("AM","").replace ("PM","")
ans=""
if a[-2:]=="PM":
if b[1]==":":
ans=str(int(b[0])+12)+b[1:]
elif b[0:2]== "12":
ans="12"+b[2:]
else:
ans=str(int(b[0:2])+12)+b[2:]
else:
if b[1]==":":
ans="0"+b[0:]
elif b[0:2]=="12":
ans="00"+b[2:]
else:
ans=b
print(ans)
+ 2
It should return in XX:XX format.For example, if I give input :
1:00 AM
it should return 01:00 not 1:00
+ 1
tnx i fixed it using zfill
0
it worked but what was my problem i did the same thing i guess adding 12 in PM except 12 PM and converting 12 AM to 00 then what was my code problem?
0
ohh shit alright tnx