We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
deftimeInWords(h,m):num_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:"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"}ifm==0:returnf"{num_words[h]} o' clock"ifm==15orm==30:returnf"{num_words[m]} past {num_words[h]}"ifm==45:next_hour=h+1ifh<12else1returnf"quarter to {num_words[next_hour]}"ifm<30:minute_word="minute"ifm==1else"minutes"returnf"{num_words[m]} {minute_word} past {num_words[h]}"next_hour=h+1ifh<12else1minute_word="minute"if(60-m)==1else"minutes"returnf"{num_words[60 - m]} {minute_word} to {num_words[next_hour]}"
Cookie support is required to access HackerRank
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 →