Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Time Converter (12h to 24h) by masloo5000
def time_converter(time):
#replace this for solution
hours=time[0:time.find(':')]
minutes=time[time.find(':')+1:time.find(':')+3]
if 'a.m.' in time:
if int(hours)<=9:
result='0'+hours+':'+minutes
elif int(hours)<12: result=hours+':'+minutes
else: result='00:'+minutes
elif 'p.m.' in time:
if int(hours)<=11:
result=str(int(hours)+12)+':'+minutes
else: result='12:'+minutes
return result
if __name__ == '__main__':
print("Example:")
print(time_converter('2: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!")
Nov. 18, 2018