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
Describe a situation in which you have experienced harm as a consequence of a failure of computer security. Was the failure mali
frutty [35]

Answer: The goals of computer security are to protect computers and users from data theft or loss as well as damage to any part of the computer.

Explanation: Common means of achieving computer security are firewalls, anti-virus software and this can fail due to hardware problems  or   weaknesses that prevent malicious attacks.

To answer this question, think of a time when you experienced any one of these. For example, personally, I was once an unfortunate victim of a general malicious attack that took advantage of a weakness in my anti-virus software. After clicking on a link on a dodgy website, a virus was installed on my computer. My computer finally crashed, without any hope of restarting it. I lost all my data and I had to buy a new computer.  This was a malicious attack.

However, sometimes people can be specifically targeted to steal their data or monitor their activities.  

7 0
3 years ago
What is e-governence?What are the advantage of it.​
kondaur [170]

Answer:

The advantages of e-government include an improved flow of information from citizen to government, government to citizen, and within government itself. Additionally, e-government helps modernize administration procedures, improving economies and promoting transparency in the process.

E-government is the use of technological communications devices, such as computers and the Internet, to provide public services to citizens and other persons in a country or region.

5 0
2 years ago
Create a list of consent rules to live by​
Agata [3.3K]
Intercourse
Kiss
Going into someone’s house
4 0
2 years ago
Which of these are part of the CPU?<br> O peripheral<br> O HDMI cord<br> O core<br> O keyboard
Makovka662 [10]
Hiii I think the best option would be C. Core
7 0
3 years ago
What is technology??
UkoKoshka [18]

Answer:

Technology is the skills, methods, and processes used to achieve goals. People can use technology to: Produce goods or services. Carry out goals, such as scientific investigation or sending a spaceship to the moon. Solve problems, such as disease or famine.

Explanation:

Good Luck!

3 0
2 years ago
Other questions:
  • Use blank to prevent friends who have been drinking from driving
    14·2 answers
  • . How is a form used?
    10·1 answer
  • Press the _______ key to move to the next cell in a row.
    12·2 answers
  • An example of a current disruptive technology is a?
    8·2 answers
  • What was the history of technology since the 1980s to now and how is it used in classrooms?.?. PLEASE HELP
    13·1 answer
  • Einstein's famous equation states that the energy in an object at rest equals its mass times the squar of the speed of light. (T
    6·1 answer
  • Having sound enhances your App, do you agree with this? Explain.
    9·1 answer
  • What is the full form of the OS?​
    15·2 answers
  • If any one has mincraft on ps4 bedrock we can finish building a BIG city world all we need to put is a shop and money dispensers
    8·2 answers
  • WRITE A PROGRAM TO CALCULATE SIMPLE INTEREST
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!