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 can a method do with a checked exception? Check the exception or ignore it. Return the exception to the sender or handle it
Serggg [28]

Answer:

Handle the exception in a catch block or throw the exception to the method that called this method.

Explanation:

The try and catch statements occur in pairs. The try statement allows the user to define a block of code to be tested for errors while it is being executed.

The catch statement allows the user to define a block of code to be executed, if an error occurs in the try block.

If an exception is checked by a method, the method either handles the exception in a catch block or throw the exception to the method calling it.

8 0
3 years ago
Read 2 more answers
What was one of the goals of the Affordable Care Act ACA ?
AveGali [126]

Make more people eligible for affordable health insurance. Consumers who live in families with incomes between 100% and 400% of the federal poverty level are given subsidies under the statute that reduce their expenditures in Act ACA.

The three main goals of the Patient Protection and Affordable Care Act (ACA) are to: (1) reform the private insurance market, particularly for individuals and small-group buyers; (2) expand Medicaid to the working poor with incomes up to 133% of the federal poverty level; and (3) alter the way that medical decisions are made. All three goals are founded on the premise that rational decision-making will be influenced by incentives but unrestricted by other factors and will primarily depend on individual decisions as opposed to government regulation. The implicit presumption is that people and organizations will behave in accordance with these reforms to create a valuable good at a reasonable cost paid by equitable risk sharing. Affordable healthcare will be the outcome.

Learn more about ACA from

brainly.com/question/29793081

#SPJ4

4 0
1 year ago
In which job role would a course in 3D modeling help with professional career prospects?
shutvik [7]
The correct answer would be a Multimedia Artist, seeing that you will be designing various models for animations, computer games, etc.
5 0
4 years ago
Read 2 more answers
Write a program to prompt the user to enter a fist name, last name, student ID and GPA. Create a dictionary called Student1 with
andrew-mc [135]

Answer:

Answered below

Explanation:

#Program is written in Python

first_name = input ("Enter first name: ")

last_name = input ("Enter last name:")

student_id = int(input("Enter your ID"))

gpa = float(input ("Enter your GPA: "))

student1 = {}

student1["first_name"] = first_name

student1["last_name"] = last_name

student1["student_id"] = student_id

student1["gpa"] = gpa

//Repeat same code for student2 and student3

class_list = {"student1": {"first_name":"joy","last_name":"Son","student_id":"1","gpa":"3.5"},

#Fill in for student 2 and 3}

#To remove GPA for all students

del class_list["student1"]["gpa"]

del class_list["student2"]["gpa"]

del class_list["student3"]["gpa"]

print(class_list)

4 0
3 years ago
___________is a standard for exchanging structured data over the web. It allows creating documents consisting of customized tags
svetlana [45]

Answer:

The answer is "XML"

Explanation:

Extensible Markup Language is a marking language, which specifies a collection of document. It uses the coding rules, which is readable for both man and computer.  

  • It is a scalable way of creating data formats and sharing structured data through the internet or private networks digitally.
  • It permits the development of custom tags to identify, transfer, verify and view data among apps and organizations.
6 0
3 years ago
Other questions:
  • These systems consist of interlinked knowledge resources, databases, human experts, and artificial knowledge agents that collect
    9·1 answer
  • THE DOMAIN IN AN EMAIL MESSAGE TELLS YOU THE
    11·1 answer
  • THE bestValue PROBLEM Using the Camera structure defined in file p1.cpp, write the function named bestValue(). The function take
    13·1 answer
  • Jerry wants to save his company money. He decides to move to open source software for his word processing needs. Jerry then down
    5·1 answer
  • Create a datafile called superheroes.dat using any text-based editor, and enter at least three records storing superheroes’ name
    9·1 answer
  • Out of a list of the values 8, 3, 30, 5, 15, and 6, what result would the MIN function return?
    9·2 answers
  • What is a fire wall and how does it work
    14·1 answer
  • Can an SQL function return multiple values? No answer needed, take the points.
    12·1 answer
  • What is the full form of ALU​
    11·2 answers
  • A menu that appears when an object is clicked with the right mouse button is called a tool-tip help menu
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!