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 BartoszKowalski
def time_converter(time):
if time == "12:00 p.m.": # dwie wyjÄ…tkowe godziny
return "12:00"
if time == "12:00 a.m.":
return "00:00"
godzina = time[:2]
minuty = time[3:5]
znak = time[-4:]
if godzina[1]==":":
godzina = "0" + godzina[0]
if minuty[1] == " ":
minuty = time[2:4]
if znak == "p.m." and int(godzina)>0 and int(godzina)<12:
godzina = str(int(godzina) + 12)
result = godzina + ":" + minuty
return result
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!")
Nov. 19, 2018