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.
numbers={0:'zero',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:'twentyone',22:'twentytwo',23:'twentythree',24:'twentyfour',25:'twentyfive',26:'twentysix',27:'twentyseven',28:'twentyeight',29:'twentynine',30:'thirty',}defhour_to_word(h):returnnumbers.get(h)defminutes_to_word(m):ifnot0<m<60:raiseValueError("Wrong value for minutes.")ifm==15orm==45:return"quarter"elifm==30:return"half"else:minutes=mifm<=30else60-mend_word='minute'ifminutes==1else'minutes'returnf"{numbers.get(minutes)} {end_word}"deftimeInWords(h,m):ifm==0:returnf"{hour_to_word(h)} o' clock"elifm<=30:returnf"{minutes_to_word(m)} past {hour_to_word(h)}"else:hour=h%12+1returnf"{minutes_to_word(m)} to {hour_to_word(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 →
Python3, not the best solution anyway