← Back to challenges

Large Numbers to English

PythonHardalgorithmsarraysstrings

Instructions

Write a function that only accepts integers and returns the English representation.

  • The function will be tested for large integers on the interval (-1e+93, 1e+93).
  • Hyphens are not used (i.e. "fifty four" not "fifty-four")
  • The word 'and' is not used (i.e. "five hundred six" not "five hundred and six").
  • Commas should be used to separate groups of numbers (see example #3, #4, and #5).

Examples

numbers_to_english(-5) ➞ "negative five"

numbers_to_english(0) ➞ "zero"

numbers_to_english(1200) ➞ "one thousand, two hundred"

numbers_to_english(123000123) ➞ "one hundred twenty three million, one hundred twenty three"

numbers_to_english(8923759857239857692) ➞ "eight quintillion, nine hundred twenty three quadrillion, seven hundred fifty nine trillion, eight hundred fifty seven billion, two hundred thirty nine million, eight hundred fifty seven thousand, six hundred ninety two"

numbers_to_english(-791283587162385761293875612) ➞ "negative seven hundred ninety one septillion, two hundred eighty three sextillion, five hundred eighty seven quintillion, one hundred sixty two quadrillion, three hundred eighty five trillion, seven hundred sixty one billion, two hundred ninety three million, eight hundred seventy five thousand, six hundred twelve"

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.