Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Time Converter (12h to 24h) by mazeua
def time_converter(time):
h, m = time.split(':')
m,n = m.split()
t={
('12','a.m.'):'00',
('1','a.m.'):'01',
('2', 'a.m.'):'02',
('3', 'a.m.'):'03',
('4', 'a.m.'):'04',
('5', 'a.m.'):'05',
('6', 'a.m.'):'06',
('7', 'a.m.'):'07',
('8', 'a.m.'):'08',
('9', 'a.m.'):'09',
('10', 'a.m.'):'10',
('11', 'a.m.'):'11',
('12', 'p.m.'):'12',
('1', 'p.m.'):'13',
('2', 'p.m.'):'14',
('3', 'p.m.'):'15',
('4', 'p.m.'):'16',
('5', 'p.m.'):'17',
('6', 'p.m.'):'18',
('7', 'p.m.'):'19',
('8', 'p.m.'):'20',
('9', 'p.m.'):'21',
('10', 'p.m.'):'22',
('11', 'p.m.'):'23'
}
return '{0}:{1}'.format(t[h,n],m)
if __name__ == '__main__':
print("Example:")
print(time_converter('12:30 p.m.'))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert time_converter('12:30 p.m.') == '12:30'
assert time_converter('9:00 a.m.') == '09:00'
assert time_converter('11:15 p.m.') == '23:15'
print("Coding complete? Click 'Check' to earn cool rewards!")
Feb. 22, 2019