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.
Inspired by this I ended up with the following Python solution:
#!/bin/python3ByOne=[0,'one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','ninteen','twenty']ByQua=["%s o' clock","quarter past %s","half past %s","quarter to %s"]foriinrange(1,10):ByOne.append('twenty %s'%ByOne[i])h,m=int(input()),int(input())hour=ByOne[h]if(m<31)elseByOne[h+1]ifnotm%15:print(ByQua[m//15]%hour)elifm<30:print("%s minute"%ByOne[m]+"s"*(m==1)+" past %s"%hour)else:print("%s minute"%ByOne[60-m]+"s"*(m==59)+" to %s"%hour)
The Time in Words
You are viewing a single comment's thread. Return to all comments →
Inspired by this I ended up with the following Python solution: