can someone help me in solvong miltitary time | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can someone help me in solvong miltitary time

im using string slicing in solving this problem cause i want to fammiliarize slicing in python but my code doesn't pass all the test case . please guide me beginner😊 def Military(time): clock = '' if time[-2] == 'P': i = time.split(':') x = i[0] y = int(x) + 12 j = i[1] converted = j[0:2] clock = f'{y}:{converted}' else: clock = f'{time[0:5]}' return clock time = input() print(Military(time))

13th Mar 2021, 3:02 AM
Restituto A. Ochea
Restituto A. Ochea - avatar
1 Answer
+ 1
The problem in your code is that it won't work on two specific scenarios. 1. At 12:00 AM where the 24 hr format should be 00:00 but your code gives 12:00 2. At 12:00 PM, where the 24 hr format should be 12:00 but your code gives 24:00 Try addressing these problems in your code.
13th Mar 2021, 3:44 AM
Abir Hasan
Abir Hasan - avatar