units = ['', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ',
'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ',
'sixteen ', 'seventeen ', 'eighteen ', 'nineteen ']
tens = ['twenty ', 'thirty ', 'forty ', 'fifty ']
def min_str(mins):
if mins < 20:
return (0 < mins < 10) * 'oh ' + units[mins]
else:
q, r = divmod(mins, 10)
return tens[q-2] + min_str(r)[3:]
def time_to_words(timestr):
hr, mins = map(int, timestr.split(':'))
outstr = "It's " + (units[hr%12] or 'twelve ') + min_str(mins)
outstr += 'am' if hr < 12 else 'pm'
return outstr
for x in ['00:00', '01:30', '12:05', '14:01', '20:29', '21:00']:
print time_to_words(x)
dW5pdHMgPSBbJycsICdvbmUgJywgJ3R3byAnLCAndGhyZWUgJywgJ2ZvdXIgJywgJ2ZpdmUgJywgJ3NpeCAnLCAnc2V2ZW4gJywgJ2VpZ2h0ICcsCiAgICAgICAgICduaW5lICcsICd0ZW4gJywgJ2VsZXZlbiAnLCAndHdlbHZlICcsICd0aGlydGVlbiAnLCAnZm91cnRlZW4gJywgJ2ZpZnRlZW4gJywKICAgICAgICAgJ3NpeHRlZW4gJywgJ3NldmVudGVlbiAnLCAnZWlnaHRlZW4gJywgJ25pbmV0ZWVuICddCnRlbnMgPSBbJ3R3ZW50eSAnLCAndGhpcnR5ICcsICdmb3J0eSAnLCAnZmlmdHkgJ10KCmRlZiBtaW5fc3RyKG1pbnMpOgogICAgaWYgbWlucyA8IDIwOgogICAgICAgIHJldHVybiAoMCA8IG1pbnMgPCAxMCkgKiAnb2ggJyArIHVuaXRzW21pbnNdCiAgICBlbHNlOgogICAgICAgIHEsIHIgPSBkaXZtb2QobWlucywgMTApCiAgICAgICAgcmV0dXJuIHRlbnNbcS0yXSArIG1pbl9zdHIocilbMzpdCgpkZWYgdGltZV90b193b3Jkcyh0aW1lc3RyKToKICAgIGhyLCBtaW5zID0gbWFwKGludCwgdGltZXN0ci5zcGxpdCgnOicpKQogICAgb3V0c3RyID0gIkl0J3MgIiArICh1bml0c1tociUxMl0gb3IgJ3R3ZWx2ZSAnKSArIG1pbl9zdHIobWlucykKICAgIG91dHN0ciArPSAnYW0nIGlmIGhyIDwgMTIgZWxzZSAncG0nCiAgICByZXR1cm4gb3V0c3RyCgpmb3IgeCBpbiBbJzAwOjAwJywgJzAxOjMwJywgJzEyOjA1JywgJzE0OjAxJywgJzIwOjI5JywgJzIxOjAwJ106CiAgICBwcmludCB0aW1lX3RvX3dvcmRzKHgp