Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following recursive function: def mystery2(s): takes a string s and does something with it if len(s) Trace the execution of the

  1. Consider the following recursive function:

    def mystery2(s): """ takes a string s and does something with it """ if len(s)  

    Trace the execution of the following call to this function.

    mystery2('bonbon') 

    To do so, complete the template that we have provided in section 1-4 section of ps3pr1. In particular, you should:

    • Fill in a separate frame for each call. We have filled in some of the components of the first call for you, and we have given you templates for up to five additional calls.

      You may not need all of the provided frames.

    • You should replace each ... with the appropriate string. In particular, the frame for each call should begin a line that explicitly states the value assigned to the parameter, as we have done for the first two calls.

    • Next, if the call is a base case, you should:

      • Replace the entire line for result_rest with the words base case.

      • Replace the ... after the word return with the value that is returned.

    • If the call is a recursive case, you should fill in the value that is being passed into the recursive call on the line for result_rest (as we have done for the first call).

    • Once you have reached the base case, you should work your way back through the sections for the previous calls. Fill in both the results of the recursive call (i.e, the value assigned to result_rest) and the value returned by the call itself.

    We took a similar approach to tracing in Task 1 of Lab 3 and Lab 4, and in Problem 2 of PS 2.

  2. What is the final result of the call mystery2('bonbon')? Put your answer in the box provided.

image text in transcribed

1-4 mystery2('bonbon') S = 'bonbon' result_rest = mystery2(...) return = mystery2(...) S = ... result_rest = return ... mystery2(...) mystery2(...) S = ... result_rest = mystery2(...) return mystery2(...) S = ... result_rest = return mystery2(...) mystery2(...) S = ... result_rest = return mystery2(...) = mystery2(...) S = ... result_rest = mystery2(...) return 1-5

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

LO3 Define job design and identify common approaches to job design.

Answered: 1 week ago

Question

Explain consumer behaviour.

Answered: 1 week ago

Question

Explain the factors influencing consumer behaviour.

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago