1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
larisa [96]
3 years ago
11

#Write a function called "replace_all" that accepts three #arguments: # # - target_string, a string in which to search. # - find

_string, a string to search for. # - replace_string, a string to use to replace every instance # of the value of find. # #The arguments will be provided in this order. Your function #should mimic the behavior of "replace", but you cannot use #that function in your implementation. Instead, you should #find the result using a combination of split() and join(), #or some other method. # #Hint: This exercise can be complicated, but it can also #be done in a single short line of code! Think carefully about #the methods we've covered. #Write your function here!

Computers and Technology
1 answer:
gulaghasi [49]3 years ago
7 0

Answer:

Here is the function replace_all:

def replace_all(target_string,find_string,replace_string):

   result_string = replace_string.join(target_string.split(find_string))  

   return result_string

#if you want to see the working of this function then you can call this function using the following statements:

target_string = "In case I don't see ya, good afternoon, good evening, and good night!"

find_string = "good"

replace_string = "bad"

print(replace_all(target_string, find_string, replace_string)

Explanation:

The above program has a function called replace_all that accepts three arguments i.e target_string, a string in which to search ,find_string, a string to search for and replace_string, a string to use to replace every instance of the value of find_string. The function has the following statement:

replace_string.join(target_string.split(find_string))  

split() method in the above statement is splits or breaks the target_string in to a list of strings based on find_string. Here find_string is passed to split() method as a parameter which works as a separator. For example above:

target_string = In case I don't see ya, good afternoon, good evening, and good night!

find_string = good

After using target_string.split(find_string) we get:

["In case I don't see ya, ", ' afternoon, ', ' evening, and ', ' night']

Next join() method is used to return a string concatenated with the elements of target_string.split(find_string). Here join takes the list ["In case I don't see ya, ", ' afternoon, ', ' evening, and ', ' night'] as parameter and joins elements of this list by 'bad'.

replace_string = bad

After using replace_string.join(target_string.split(find_string))  we get:

In case I don't see ya, bad afternoon, bad evening, and bad night!  

The program and output is attached as a screenshot.

You might be interested in
What is the energy conversion and the law used in the given scenario?
Natali [406]

Answer:

The correct options are;

Mechanical

Faraday

Explanation:

The principle of working of electric generators is to convert kinetic energy, which is the energy present in the spinning turbine into electrical energy. Electricity is generated by the use of the electric generators has the largest share of all forms of electricity generated electricity and it is based on Faraday's law of of induction, which states that Emf = N×(ΔФ/Δt)

Where;

Emf = The induced voltage

ΔФ = Change in magnetic flux

Δt = Change in time.

Therefore, we have;

Traditional power-generating stations do not store electrical energy. In such power stations, the original energy source spins a turbine which an electric generator. It converts <u>mechanical </u>energy into electrical energy using a fundamental principle of physics called <u>Faraday's</u> law.

3 0
3 years ago
The vast majority of the population associates Blockchain with cryptocurrency Bitcoin; however, there are many other uses of blo
nydimaria [60]

Blockchain with cryptocurrency Bitcoin; however, there are many other uses of blockchain; such as Litecoin, Ether, and other currencies. In this discussion, Explanation:

4 0
3 years ago
In a(n) ____ design, the remote user's keystrokes are transmitted to the mainframe, which responds by sending screen output back
Harrizon [31]

Answer:

I think it would be centralized

4 0
3 years ago
In a clustered column chart, the names of each column are part of the ____ series. select one:
Ratling [72]
Data.......;...............;.........;......;.
4 0
3 years ago
Read 2 more answers
Which string method returns true if the character is a lowercase letter?
Llana [10]
The right answer is : is.lower(letter)
8 0
3 years ago
Other questions:
  • In 2-5 paragraphs, describe the points that Kendra needs to consider when choosing a telecommunications technology to meet her n
    6·1 answer
  • List five characteristics of a series circuit
    9·1 answer
  • Network and web0based software used for workplace collaboration is commonly called?
    11·1 answer
  • A spreadsheet is a software program for storing, managing, and retrieving information. true or false?
    15·2 answers
  • One cost of starting your own business is _____.
    12·1 answer
  • "the most common way to access the internet is through ________."
    5·1 answer
  • ∑_(A,B,C,D,E)▒〖(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)〗
    8·1 answer
  • Please write a complete program to calculate monthly payment given
    15·1 answer
  • Cryptanalysis is made more difficult by having shorter keywords.a) trueb) false
    6·1 answer
  • In a digit 13 ISBN number, can you think of errors that the check digit system cannot identify and give an example to explain wh
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!