+ 1

Analogue to military time bug fixing?

Using python, I feel I am rather close, but still outputs some errors. Any help at all would be greatly appreciated! 🖤 https://code.sololearn.com/cI58oxVvvimj/?ref=app

8th Apr 2023, 4:04 AM
Matt Osmond
Matt Osmond - avatar
2 Respuestas
+ 4
Ultimately you may only need to change line 35 to make it work properTime = militaryTranslate[0:1] + ":" + militaryTranslate[2:3] Remember in a slice, the end index is not included. So the first two characters are [0:2] and the next two are [2:4]
8th Apr 2023, 5:44 AM
Tibor Santa
Tibor Santa - avatar
+ 4
Hi. I reviewed your code. You could get rid of "else: pass" lines, they don't do anything just clutter the code, the result is the same without them. You have two distinct cases AM and PM, you could also write this condition like so: if 'AM' in circleTime: ... else: ... Using slightly shorter variable names could make the code vastly more readable. My main suggestion is to put your code inside a function, because then you can immediately write some test cases to verify how it works. Particularly you have to test single and double digit hours. 0:12 AM 0:12 PM 11:00 AM 11:00 PM And it's a question if the 24 hour format expexts leading zeroes for single digit hour or minute: 1:05 AM is represented as 1:5 or 1:05 or 01:05? Your code actually seems to cut the last decimal of the hours and minutes. 12:00 PM may also be a special case (midnight) in 24h format would be 00:00 Your approach can work but you have to elaborate your algorithm to cover all these cases correctly.
8th Apr 2023, 5:35 AM
Tibor Santa
Tibor Santa - avatar