Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
roor solution in Clear category for Time Converter (12h to 24h) by Sebulba_13
def time_converter(time):
if time[:2] == '12':
return time[:5] if time[-4:] == 'p.m.' else '00' + time[2:5]
else:
return '0' + time[:4] if time[-4:] == 'a.m.' else str(int(time[:len(time) - 8]) + 12) + time[len(time) - 8:len(time) - 5]
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!")
June 22, 2020