You are viewing a single comment's thread. Return to all comments →
words = { 1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", 20: "twenty", 21: "twenty one", 22: "twenty two", 23: "twenty three", 24: "twenty four", 25: "twenty five", 26: "twenty six", 27: "twenty seven", 28: "twenty eight", 29: "twenty nine" } if m == 0: return f"{words[h]} o' clock" elif m == 30: return f"half past {words[h]}" elif m < 30: if m == 15: return f"quarter past {words[h]}" elif m == 1: return f"one minute past {words[h]}" else: return f"{words[m]} minutes past {words[h]}" else: difference = 60 - m if m == 45: return f"quarter to {words[(h % 12) + 1]}" elif difference == 1: return f"one minute to {words[(h % 12) + 1]}" else: return f"{words[difference]} minutes to {words[(h % 12) + 1]}"
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
The Time in Words
You are viewing a single comment's thread. Return to all comments →