Question
Verbalize a Number The goal of this programming project is spell out large numbers in English. Here, the number will be between 0 and 999,999,999
Verbalize a Number
The goal of this programming project is spell out large numbers in English. Here, the number will be between 0 and 999,999,999 (both inclusive). You should break this problem down in multiple simple functions that work together.
Step 1: Spelling a single digit
The first step involves writing a function called sayDigit that takes a number from 0 to 9 and returns a text string for that number in English. For example, the function should return the string "five" for the input number 5. There are different ways of solving it such as a chained conditional or a list of strings.
Before moving to step 2, you should test your function on different numbers by adding the following two lines to the end of your program (these lines should be changed later to support larger numbers):
n = int(input()) print(sayDigit(n))
Step 2: Spelling small numbers
Before moving on the hundreds, thousands and millions, you should write a second function (such as sayTeen) that can handle numbers between 0 and 19. Here, you can re-use your previously defined function sayDigit to handle the case that the number is less than 10 and include additional Python code for numbers between 11 and 19.
Again, you should test your function to see that how it works before continuing to step 3.
Step 3: Spelling large numbers
In order to solve the problem for large numbers, you should continue the same process of defining more and more functions to break down the problem into smaller parts that can be handled by other functions. This way, you can handle two-digit numbers up to 99, then three digit numbers, thousands and finally millions. Also, you should print an error message and quit the program if the number is larger than 999,999,999.
Hint: You might want to use the integer division (//) and remainder (%) operators for this problem.
Example Interactions (each interaction is running the program once):
< 5 > five < 23 > twenty-three < 82379 > eighty-two thousand three hundred seventy-nine < 932000719 > nine hundred thirty-two million seven hundred nineteen < 0 > zero
(Here, lines starting with > indicate output from the program and lines starting with < indicate input.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started