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 krk05
def time_converter(time):
#replace this for solution
if time[-4:] == "a.m.":
if time[1] == ":":
wynik = time[:4].zfill(5)
return wynik
if time[:2] == "12":
return "00" + time[2:5]
wynik = time[:5]
return wynik
elif time[-4:] == "p.m.":
a = time[:2]
if a == "12":
return a+time[2:5]
if a.find(":") == -1:
b = int(a)+12
if b == 24:
b = str("00")
return str(b)+time[2:5]
else:
a = time[:1]
b = int(a) + 12
return str(b) + time[1:4]
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. 17, 2018