Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)!!!

image text in transcribed

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

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_2

Step: 3

blur-text-image_3

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 Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Explain DNS Resource Records, SOA, A, MX, CNAME, PTR.

Answered: 1 week ago