Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IT IS PYTHON! PLEASE RUN IT TO SEE IF IT WORKS BEFORE POSTING HERE, THANKS. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Write a Python function called print_letters that takes a

IT IS PYTHON! PLEASE RUN IT TO SEE IF IT WORKS BEFORE POSTING HERE, THANKS.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Write a Python function called print_letters that takes a single digit positive integer as an argument, and then prints an integer representing the number of letters in the English spelling of that value, as seen in the chart below:

1 -> One -> 3 4 -> Four -> 4 7 -> Seven -> 5

2 -> Two -> 3 5 -> Five -> 4 8 -> Eight -> 5

3 -> Three -> 5 6 -> Six -> 3 9 -> Nine -> 4

A sample run is shown below:

>>> print_letters(7)

5

2). Write another function in the same file called return_letters that does the same thing as above, but it returns the number of letters rather than printing it.

3). What will be the result of running each of the following? Explain to your TA which ones will cause errors, and why.

>>> print_letters(1) + print_letters(9)

>>> return_letters(1) + print_letters(9)

>>> return_letters(1) + return_letters(9)

>>> return_letters(print_letters(8))

>>> print_letters(return_letters(8))

4). Write a function most_letters that takes in three single digit numbers, and returns the one that has the most letters in its English spelling. In the case of a tie for the most, print "Tie!" instead, and return nothing. You must call either print_letters or return_letters as part of your function, and be prepared to explain to your TA why you didnt/couldnt use the other one.

Hint: There are four cases to consider: the first number has more letters than the other two, the second number has more letters than the other two, the third number has more letters than the other two, or none of the above (in which case there must be some form of tie for the most).

Examples (output in bold is returned, output in italics is printed):

>>> most_letters(9, 8, 5)

8

>>> most_letters(5, 1, 2)

5

>>> most_letters(7, 6, 3)

Tie!

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

What practical considerations are deterrents to using the SOT rule?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago