Using Python, we want to convert words into numbers. In this challenge, we will explore how to convert a string into an integer.
The strings simply represent the numbers in words. Let’s convert these words into numbers.
- “one” => 1
- “twenty” => 20
- “two hundred forty-six” => 246
- “seven hundred eighty-three thousand nine hundred and nineteen” => 783919
- The minimum number is “zero” (inclusively)
- The maximum number, which must be supported is 1 million (inclusively)
- The “and” in e.g. “one hundred and twenty-four” is optional, in some cases it’s present and in others, it’s not
- All tested numbers are valid, you don’t need to validate them
Test cases to convert words into numbers
The solution in Python to convert words into numbers