Question: Only using recursion! Do not use loop(for)!!! Note: You are not allowed to use any of the string methods for this question (remember: slicing, in,

Only using recursion! Do not use loop(for)!!!

Only using recursion! Do not use loop(for)!!! Note: You are not allowed

Note: You are not allowed to use any of the string methods for this question (remember: slicing, in, and len are not string methods, thus they are allowed). Write a Python function replace_str that consumes 3 non-empty strings, base, target and rep. The first string, base, represents a base string that you want to update. The second string target represents the target string that you want to replace and the third string rep represents a string that will replace the target in the updated string. The function returns a new string in which the target string is replaced by the rep string in the base string, but returns the same base string if either of the following conditions hold true. If the target string is not found in the base string or, If the target and rep are the same strings. For example, replacestr ("This is a book", "a", "the")=> ' This is the book' replacestr ("This is my book", "a", "the"->'This is my book' replace_str ("my brother reads books and sometimes he reads magazines", "reads", "likes") => 'my brother ikes books and sometimes he likes magazines replace_str ("Apple is a fruit", "f" , "t")-> Apple is a truit' replacestr ("aaaaa", "aa", "X")=> 'xxa

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!