Question: Question 5 This question will be about reversing strings by parts. What we mean by that is that let's say we have a string Nabi.

 Question 5 This question will be about reversing strings by parts.What we mean by that is that let's say we have a

Question 5 This question will be about reversing strings by parts. What we mean by that is that let's say we have a string "Nabi. If we want to reverse "Nabi" by parts with n=1 we only reverse the first 1..n letters which in this case is only "N so the string stays the same and the output is "Nabi. When n=3 (think of this as reversing str[:3]) is when things start to get interesting. We need to reverse the string with n=1..n meaning we first carry out the operation for n=1 then n=2 and n=3 in that order. With n=1, we get "Nabi, with n=2 operated on that output we flip the first 2 characters of "Nabi" and get "aNbi, and with n=3 operated on that output we flip the first 3 characters of "aNbi" and get "bNai. Write the code for the following questions with this knowledge. Restriction (for both parts): 1. Do input validation. 2. No loops or map can be used, only recursion. Question 5.1 Write a function that reverses the string input string by parts at intervals 1 to n. def recursive_reverse_up_to_n (name, n): Recursively reverses the given string at chunks 1..n Restrictions: You should use recursion. You should do input validation. Parameters: name (str): The string to be reversed n (int): How many times the string should be reversed Returns: (str) Reversed string with the given formula >>> recursive_reverse_up_to_n('Nabi', 3) 'bNai' >>> recursive_reverse_up_to_n('klmn', 3) 'mkin' >>> recursive_reverse_up_to_n('klmn', 4) 'nlkm' +++++++++++++++++++++++++ WRITE YOUR DOCTESTS BELOW +++++++++++++++++++++++++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!