+ 1
Can someone tell me what's wrong with my code?? I'm trying the military time problem in the code coach. But i only get 2/5
time = input() meridian = ''.join(time[5:]) if 'AM' in time: print(''.join(time[0:5])) else: mil_time = int(''.join(time[0:2])) mil_time += 12 mil_time = str(mil_time) time = list(time) mil_time = list(mil_time) for i in range(2): time[i] = mil_time[i] print(''. join(time[0:5]))
3 odpowiedzi
+ 2
Input => 22:00 AM
✅ expected output => 00:00
❌ But your code outputs => 12:00
+ 1
ghali lawal
There are two bugs in your code
1) Output Format is given in the problem statement to be:
A string that includes the time in a 24 hour format (XX:XX)
But when
1:00 AM is given as an input then output of the code is 1:00 but the expected output is 01:00
2) the input in PM gives error
+ 1
Arsenic Smiley thanks guys for the help. I've rectified those issues that you raised but the hidden test case 4 keeps raising an error. Below is the corrected code:
time = input()
meridian = ''.join(time[5:])
if 'AM' in time:
if ''.join(time[0:2]) == '12':
time = time.replace('12','00')
print(''.join(time[0:5]))
exit()
if len(time) == 7:
part = '0' + time[0]
time = part + time[1:4]
print(time)
if len(time) == 8:
print(''.join(time[0:5]))
else:
if ''.join(time[0:2]) == '12':
print(''.join(time[0:5]))
exit()
mil_time = int(''.join(time[0:2]))
mil_time += 12
mil_time = str(mil_time)
time = list(time)
mil_time = list(mil_time)
for i in range(2):
time[i] = mil_time[i]
print(''. join(time[0:5]))