← Back to challenges

English to Numbers

PythonHardconditionsnumbersstrings

Instructions

This is a companion to my previous challenge.

Given an English description of an integer in the range 0 to 999, devise a function that returns the integer in numeric form.

Examples

eng2nums("four") ➞  4

eng2nums("forty") ➞ 40

eng2nums("six hundred") ➞ 600

eng2nums("one hundred fifteen") ➞ 115

eng2nums("seven hundred sixty seven") ➞ 767

Notes

  • No hyphens are used in test cases ("twenty three" not "twenty-three").
  • The word "and" is not used: "one hundred three" not "one hundred and three".
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.