Military time codecoach problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

21st Nov 2022, 6:25 PM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
6 Answers
+ 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
6th Mar 2023, 5:38 PM
Chuks AJ
Chuks AJ - avatar
+ 6
nabeer zahed chowdhury , can you link your code here?
21st Nov 2022, 8:21 PM
Lothar
Lothar - avatar
+ 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*.
23rd Nov 2022, 5:56 PM
Lothar
Lothar - avatar
+ 2
Sorry I forgot to attach to the original question even tho I intended to lol
22nd Nov 2022, 10:23 PM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
+ 2
Lemme add some comments.. edit: Done... take another look... n thanks!
25th Nov 2022, 3:53 PM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
22nd Nov 2022, 10:23 PM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar