+ 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
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.
+ 8
What about midnight?
+ 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))
+ 2
Thank guys
+ 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 ;)