Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function that takes a whole number as parameter and returns a string containing the number spelled out in English. For example, the function

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Write a function that takes a whole number as parameter and returns a string containing the number spelled out in English. For example, the function call: spell (123123) will return the string: one hundred twenty three thousand one hundred twenty three Your function must work for any whole number whose value is between -999,999,999 and 999,999,999. Of course, the numbers will not have commas in Python. Your function spell will do NO PRINTING; instead, it will return a string containing the appropriate words. I have provided you with four function definitions that will help you in defining function spell). You will find these function definitions in a source code file here E. You are required to use these functions in your solution. Start by becoming familiar with what these four functions do. Read the comment for each function. Write a test program that calls each of these four functions and prints their returned values. Do not modify any of these functions in any way. Finally, you can read the full definition for each of these given functions if you want to, though that is certainly not necessary in order to use them effectively Once you thoroughly understand how to call each of those four functions and what they will return, it is time to write your own function definition for function spell0. The definition for function spell0 that you write will be inside the same source code file as the other given function definitions. More importantly, the definition for function spell) that you write will call these other functions either directly or indirectly. The trick to defining your own function is to always write the test program first, before you try to write the definition itself. Here is a sample test program for your function spell0. This exact test program must print the appropriate words to the console: print (spell (123456789)) print (spell (456678)) print (spell (66)) print (spell -123456789)) print (spell (-456678)) print (spell (-418)) print (spell (e)) print (spell (1e004) # should print "zero" without the quotes Before you can start writing the definition for function spell. you need to be able to write down what output you want this program to generate when you are finished with this assignment. You might find this website useful in telling what the returned values from your spell) function should look like: However that website does not handle negative numbers and your function spell0 has to. Also, the use of the word "and" and the additional commas that this website includes are not necessary for your function to generate. In order to receive full credit: Your program (which includes at least five function definitions) can have no duplicate code: the names of the numbers must appear only once in your whole source code file. .The function you define must be named "spell The function you define must have a comment telling what the function does with its parameter(s) and what (if anything) it returns. Your function spell) must not do any printing. .You must not modify the functions I gave you in any way Rubric for Spelling Numbers Criteria Ratings Pts Function spell) returns the correct string for all numbers 1.0 pts 0.0 pts 1.0 pts Function spell) contains no duplicate code 1.0 pts 0.0 pts 1.0 pts Function spell) does not input and no printing 1.0 pts 0.0 pts 1.0 pts Function spell) contains a complete and correct comment 1.0 pts 0.0 pts 1.0 pts All other program guidelines are followec 1.0 pts 0.0 pts 1.0 pts Total Points: 5.0 def digitName (digit): Returns a string containing the English word naming "digit". "digit" must be between 1 and 9, inclusive if digit1: name -"one " elif digit2: name "two elif digit == 3: name- "three " elif digit4: name -"four " elif digit5: name-"five " elif digit6: name-"six" elif digit == 7: name- "seven " elif digit 8: name- "eight " elif digit9: name - "nine" else: name "" return name def teenName (number) Returns a string containing the English word naming "number". "number" must be between 10 and nineteen inclusive. if number == 10: name = "ten " elif number == 11: name = "eleven " elif number == 12: name- "twelve " elif number 13: name "thirteen" elif number 14: name "fourteen" elif number 15: name -"fifteen" elif number 16: name "sixteen" elif number 17: name- "seventeen " elif number == 18: name- "eighteen " elif number 19: name- "nineteen " else: name "" return name def tensName (number) Returns a string containing the English word for just the tens part of "number" must be an integer between 20 and 99 inclusive if number 90: name "ninety" elif number80: name"eighty " elif number 70: name"seventy " elif number 60: name"sixty " elif number 50: name"fifty " elif number >= 40: name = "f rty " elif number 30: name"thirty " elif number >= 20: name = "twenty " else: name- "" return name def spel1NumberLessThanThousand (number) Returns a string containing the English words that spell out "number" "number" must be between 0 and 1000, exclusive part number # the part that still needs t be converted name"" if part 100: # the name of the number name - digitName (part //100) + "hundred " part = part % 100 if part 20: namename tensName (part) part-part % 10 elif part >- 10 (part) name name + teenName part0 if part >0: namename + digitName (part) return name

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions