+ 2
Military time codecoach problem
I need some help, test case 3 and 5 are failing. Is there anything I have missed to account for?
6 Respostas
+ 2
This could be solved a lot quicker using the datetime module which does all the formatting for you:
https://code.sololearn.com/c2DBQF02jziy/?ref=app
+ 6
nabeer zahed chowdhury ,
can you link your code here?
+ 3
nabeer zahed chowdhury ,
the code that you have provided can look a little bit confusing, because a lot of if... elif... else... statements and nested statements are used. we also have 5 different lines for output, and they also differ in formating, access of the input values and so on. i would recommend to re-think about the way we are going.
> to get the task done, it is recommended to do a proper splitting of the 3 input parts first.
we can use a list and fill it with *hour* (as int),*minute* (as int) an *am_pm* (as string). so the list should be: [1, 25, 'AM'] when '1:25 AM' is given as input.
> we only have to check if the time given is *PM*. if yes: add + 12 to the hour in the list.
> now we can output the result. to get the numbers for hours and minutes zero-padded, we can use an f-string with a format specifier like: print(f'{hour:02}:{minute:02}'). the output for the mentioned input will be: *01:25*.
+ 2
Sorry I forgot to attach to the original question even tho I intended to lol
+ 2
Lemme add some comments..
edit: Done...
take another look... n thanks!