convert 12 hours to 24? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

18th Jun 2021, 12:52 PM
Hasan
Hasan - avatar
5 Answers
+ 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)
18th Jun 2021, 12:57 PM
dead falcon
+ 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
18th Jun 2021, 1:02 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
tnx i fixed it using zfill
18th Jun 2021, 1:08 PM
Hasan
Hasan - avatar
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?
18th Jun 2021, 1:02 PM
Hasan
Hasan - avatar
0
ohh shit alright tnx
18th Jun 2021, 1:04 PM
Hasan
Hasan - avatar