Editor

Test a 12-Hour Clock Converter

Write the tests · Intermediate · about 12 min

to_12_hour(time) takes a 24-hour time as text, always two digits, a colon and two digits, from "00:00" to "23:59". It returns the 12-hour time as text: the hour with no leading zero, a colon, the two minute digits, a space, and AM for times before noon or PM from noon on. The 00 hour shows as 12 AM and the 12 hour shows as 12 PM.

Write test_ functions with assert that pass on a correct version and fail on broken ones.

Examples

to_12_hour("09:05")    # "9:05 AM"
to_12_hour("13:45")    # "1:45 PM"
to_12_hour("23:59")    # "11:59 PM"
def test_afternoon():
assert to_12_hour("13:45") == "1:45 PM"
The solution opens after your first Check.