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):numDict={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',30:'thirty'}isOverHalf=int(m>30)m=60-mifisOverHalfelsemifm==0:returnf"{numDict[h]} o' clock"ifm%15==0:s="quarter"ifm==15else"half"else:s=f"{'twenty ' if m>20 else ''}{numDict[m%20]} minute{'s' if m>1 else ''}"returnf"{s} {'to' if isOverHalf else 'past'} {numDict[h+1 if isOverHalf else h]}"
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 →
py