+ 1

Military hour

Hello guys I’m stuck at the Military hour problem, I have one case still incorrect Thanks The code : https://code.sololearn.com/cjPEneGWiOBk/?ref=app

20th Apr 2023, 4:05 PM
Julien Badii
5 Answers
+ 12
1:25 AM outputs 1:25 and not 01:23 in four digits. There will be needed to add one digit up to 9:59.
20th Apr 2023, 4:24 PM
JaScript
JaScript - avatar
+ 8
What about midnight?
20th Apr 2023, 4:18 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
import re usTime = re.search(r'(\d?\d):(\d\d) (A|P)M', input()) hours = int(usTime.group(1)) minutes = usTime.group(2) indicator = usTime.group(3) if indicator == 'P': hours += 12 elif hours == 12: hours = 0 print('%02d:%s' % (hours, minutes))
22nd Apr 2023, 5:59 AM
Vaibhav
Vaibhav - avatar
+ 2
Thank guys
20th Apr 2023, 8:36 PM
Julien Badii
+ 1
Just a tip: try to keep your code simpel as possible. Less complex code is always better. E.g you can access dict values with a variable as key, instead of iterating over the list. You could also just add 12 to the hour if its pm to simplify it even more ;)
21st Apr 2023, 11:13 PM
MrGrumpy
MrGrumpy - avatar