You are viewing a single comment's thread. Return to all comments →
Python 3 solution:
def number_to_words(number): number_word_dictionary = { 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: 'quarter', 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', 30: 'half' } return number_word_dictionary[number] def timeInWords(h, m): if m > 30: hours = number_to_words(h + 1) minutes = number_to_words(60 - m) past_or_to = 'to' elif m > 0: hours = number_to_words(h) minutes = number_to_words(m) past_or_to = 'past' else: hours = number_to_words(h) return hours + ' ' + "o' clock" if m == 1: return minutes + ' minute ' + past_or_to + ' ' + hours if m == 15 or m == 30 or m == 45: return minutes + ' ' + past_or_to + ' ' + hours else: return minutes + ' minutes ' + past_or_to + ' ' + hours
Seems like cookies are disabled on this browser, please enable them to open this website
The Time in Words
You are viewing a single comment's thread. Return to all comments →
Python 3 solution: