Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Time Converter (24h to 12h) by tlewandster
def time_converter(time: str) -> str:
hours, minutes = time.split(':')
am_pm = 'p.m.' if int(hours) > 11 else 'a.m.'
hours = int(hours) - 12 if int(hours) > 12 else int(hours)
return f'{hours or 12}:{minutes} {am_pm}'
print("Example:")
print(time_converter("12:30"))
assert time_converter("12:30") == "12:30 p.m."
assert time_converter("09:00") == "9:00 a.m."
print("The mission is done! Click 'Check Solution' to earn rewards!")
June 29, 2023
Comments: