answer.
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
mojhsa
13 days 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:
oksian1 [804]13 days ago
7 0

Answer:

Here is the function called replace_all:

def replace_all(target_string,find_string,replace_string):

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

   return result_string

#To see how this function operates, you can invoke it using the following code:

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 aforementioned program contains a function named replace_all that accepts three parameters: target_string, which is the string to search within; find_string, which is the string you are searching for; and replace_string, which is the string utilized to replace all occurrences of find_string. The function executes the following statement:

replace_string.join(target_string.split(find_string))  

The split() method in this context divides target_string into a list according to find_string. Here, find_string is provided to the split() method as a parameter, acting as a separator. For example:

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

find_string = good

After executing target_string.split(find_string), we obtain:

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

The join() method then concatenates the elements of the list generated by target_string.split(find_string). Here, join takes that list as a parameter and connects its elements using 'bad'.

The resulting replace_string = badSubsequently, after using replace_string.join(target_string.split(find_string)), we generate:

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

The code and output are attached as a screenshot.

You might be interested in
Question #5<br> How does the computer decide which path to follow in a selection control structure?
Harlamova29_29 [932]

Answer:

In my opinion, the coding structure's elements assist the software or CPU in interpreting or directing the programming.

Explanation:

6 0
25 days ago
List at least six things you would check for if you were asked to evaluate the workspace of an employee for ergonomics
maria [879]

Evaluating the risks related to employees remaining stationary for extended periods at their workstations is critical. Below is a compilation of key ergonomic principles that aid in identifying ergonomic risk factors.


<span>1.    </span>Are employees kept in a neutral posture?

<span>2.    </span>Does the workstation provide opportunities for movement and stretching?

<span>3.    </span>Is the lighting sufficient?

<span>4.    </span>Are the chairs adjustable as needed?

<span>5.    </span>Are suitable footrests available?

<span>6.    </span>Is there additional storage to enhance desk organization?






0 0
1 month ago
Suppose a linked list of 20 nodes. The middle node has a data –250. Write the pseudocode to replace the middle node of the linke
oksian1 [804]
The data for the middle node shows as –250.... Please outline the pseudocode to substitute the middle node in the linked list. Assume that the head pointer is designated as Head_ptr and the entry data for the new node is defined as Entry.
4 0
21 day ago
Read 2 more answers
CHALLENGE ACTIVITY 2.1.2: Assigning a sum. Write a statement that assigns total_coins with the sum of nickel_count and dime_coun
Harlamova29_29 [932]

Answer:

In Python:

total_coins = nickel_count + dime_count

Explanation:

The sums of nickel_count and dime_count are combined and assigned to total_coins.

Cheers.

8 0
29 days ago
Which selections are possible for controlling the start time of audio playback? Check all that apply. Automatic Rewind when done
maria [879]

Selecting the option to trim audio upon clicking would be your best answer

5 0
12 days ago
Other questions:
  • Why were the practitioners of alternative software development methods not satisfied with the traditional waterfall method?
    9·1 answer
  • The Pentium 4 Prescott processor, released in 2004, had a clock rate of 3.6 GHz and voltage of 1.25 V. Assume that, on average,
    8·1 answer
  • In the middle of the iteration, how should a team handle requirement changes from the customer? (1 correct answer)
    7·2 answers
  • Which of the following is true of how computers represent numbers?
    9·2 answers
  • When a CPU executes instructions as it converts input into output, it does so with
    12·1 answer
  • More Loops: All versions of foods.py in this section have avoided using for loops when printing to save space. Choose a version
    13·1 answer
  • 5.15 LAB: Output values below an amount Write a program that first gets a list of integers from input. The input begins with an
    9·2 answers
  • To finish creating a design for the webpage, use one shape to cut away part of the other. Create a 700 pixel by 700 pixel square
    10·1 answer
  • explain why entrepreneurial activities are important to social development and progress of the econo​
    9·1 answer
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!