#155 · Strings · Advanced · 140 XP · about 30 min
Cheques, invoices and voice assistants need numbers written out in words. Write to_words(n) that returns the English words for the whole number n, in lowercase, following these rules:
to_words(42) # returns 'forty-two' to_words(1005) # returns 'one thousand five' to_words(7000210) # returns 'seven million two hundred ten'
7,000,210 splits into the groups 7, 000 and 210: "seven million", nothing for the empty thousands, then "two hundred ten".
0 <= n <= 999,999,999,999Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.