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