Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that asks the user for a positive integer between 0 and 1 billion, exclusive, then prints the number as a text string.
Write a program that asks the user for a positive integer between and billion, exclusive, then prints the number as a
text string. For example, the number will be printed as: two thousand twentyfour.
Background info on how to form number strings:
A large integer is divided into digit triplets, often separated by a comma. For example:
For a number up to billion there are up to triplets: millions, thousands, and ones. For example: has
million as the first triplet, thousand as the second triplet, and as the third triplet.
For each triplet there are place values: hundreds, tens, and ones. For example: has hundreds, tens, ones.
The tens are divided into types:
o From the tens text strings are twenty, thirty, forty... and can optionally go with a ones value.
If there is a ones value, then there is a dash in between the tens and ones values. For example: twentythree
o From the text strings are ten, eleven, twelve, thirteen... and there is no ones value because it's already
'builtin
Download the file convert.py which has convert functions: toTens, toTeens, and toOnes
The function toTens accepts a number in the range as input argument, and returns the equivalent text strings
'twenty' to 'ninety'.
The function toTeens accepts a number in the range as input argument, and returns the equivalent text strings
'ten' to 'nineteen'.
The function toOnes accepts a digit in the range as input argument, and returns the equivalent text strings 'one' to
'nine'.
Follow these steps to complete the lab assignment:
At the top of your source file, import the convert.py module with: import convert
Note that theres no py in the import statement
Write a function getInput that will:
ask the user for a positive integer under billion.
keep prompting until you get an integer between and billion, exclusive
if the user input is not an integer or is out of range, print an error message
the user can optionally use commas in the input number. Quietly remove the comma which means no printing
to screen that the comma is removed You don't have to check whether the comma is at the right location in
between triplets
Write a function toWords that will:
check if there is the first triplet in the number the millions and if it exists, call the convertTriplet function to
convert the millions triplet to a text string.
check if there is the second triplet in the number the thousands and if it exists, call the convertTriplet function
to convert the thousands triplet to a text string.
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