Question: Take a look at the following recursive function: def mystery (1st): if 1st == []: return [] return [1st [0]-5]+mystery (1st [1:]) Both partners

Take a look at the following recursive function: def mystery (1st): if 1st == []: return [] return [1st I b. What does this function do, in a single sentence? c. What is the base case? d. Does the recursive case

Take a look at the following recursive function: def mystery (1st): if 1st == []: return [] return [1st [0]-5]+mystery (1st [1:]) Both partners should be prepared to respond to the prompts below before getting checked off by the TA. If you're not confident in your answers, discuss them with a TA before moving onto the second warm-up problem. For this first problem, write your answers in the comments within your code (they don't need to be detailed). else: I a. Type out a step by step sequence, similar to what's shown above for fact_recursion(5), for what would happen if you called mystery([5, 3, 7]). You may want to consider putting in some print statements and running the function to ensure you're on the right track. Remember that 1st[1:] makes a copy of Ist with the first element removed] I b. What does this function do, in a single sentence? c. What is the base case? d. Does the recursive case (also called the reduction step) always move towards the base case? Explain why or why not. e. Write an equivalent function using a loop rather than recursion.

Step by Step Solution

3.46 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres an analysis of the given recursive function def mystery1st if 1st return else retu... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!