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
Write a program that will ask the user for a set of ten numbers. After all ten numbers have been entered, the program will displ
muminat

Answer:

In Python:

nums = []

larg= []

small = []

while True:

   for i in range(10):

       num = int(input(": "))

       nums.append(num)

   print("Smallest: "+str(min(nums))); print("Largest: "+str(max(nums)))

   larg.append(max(nums))

   small.append(min(nums))

   another = int(input("Press 1 to for another sets: "))

   nums.clear()

   if not another == 1:

       break

   

print("Average Large: "+str(sum(larg)/len(larg)))

print("Average Small: "+str(sum(small)/len(small)))

Explanation:

This initializes the list of input numbers

nums = []

This initializes the list of largest number of each input set

larg= []

This initializes the list of smallest number of each input set

small = []

This loop is repeated until, it is exited by the user

while True:

The following iteration is repeated 10 times

   for i in range(10):

Prompt the user for input

       num = int(input(": "))

Add input to list

       nums.append(num)

Check and print the smallest using min; Check and print the largest using max;

   print("Smallest: "+str(min(nums))); print("Largest: "+str(max(nums)))

Append the largest to larg list

   larg.append(max(nums))

Append the smallest to small list

   small.append(min(nums))

Prompt the user to enter another set of inputs

   another = int(input("Press 1 to for another sets: "))

Clear the input list

   nums.clear()

If user inputs anything other than 1, the loop is exited

<em>    if not another == 1:</em>

<em>        break</em>

Calculate and print the average of the set of large numbers using sum and len    

print("Average Large: "+str(sum(larg)/len(larg)))

Calculate and print the average of the set of smallest numbers using sum and len

print("Average Small: "+str(sum(small)/len(small)))

8 0
2 years ago
Which of the following websites can help you learn about general career trends?
Ber [7]
The answer is vocational information center as this area or website provides a person or a student to explore careers that could be suitable to his or her liking and to show careers or professions' role as they work. This website is a way of educating an individual of having to provide informations regarding about careers.
8 0
2 years ago
The internet is ________. an internal communication system for businesses a large network of networks a communication system for
uranmaximum [27]

A large network of networks

<h3>What Is a large network?</h3>
  • It is the biggest network that connects computers across the world. With the internet, people can share data and files over the internet. The Internet is defined as a network of networks Hence it is the correct option

To learn more about the network, refer

to https://brainly.in/question/32165678

#SPJ4

4 0
1 year ago
Which of the following is NOT a common grammar adjustment which is identified by grammar-check software?
Sedbober [7]

Answer:

Shortened versions of phrases Ex:(l ol, s mh, i dk, ect.)

Explanation:

Hope that this helps, if you have any more question please feel free to contact me, hope you have an amazing rest of your day. ;D

7 0
2 years ago
C++
Cerrena [4.2K]

Answer:

#include <iostream>

#include<iomanip>

using namespace std;

double DrivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon)

{

  double dollarCost = 0;

  dollarCost = (dollarsPerGallon * drivenMiles) / milesPerGallon;

  return dollarCost;

}

int main()

{

  double miles = 0;

  double dollars = 0;

  cout << "Enter miles per Gallon   : ";

  cin >> miles;

  cout << "Enter dollars per Gallon: ";

  cin >> dollars;

  cout << fixed << setprecision(2);

  cout << endl;

  cout << "Gas cost for 10 miles : " << DrivingCost(10, miles, dollars) << endl;

  cout << "Gas cost for 50 miles : " <<DrivingCost(50, miles, dollars) << endl;

  cout << "Gas cost for 400 miles: "<<DrivingCost(400, miles, dollars) << endl;

  return 0;

}

Explanation:

  • Create a method definition of DrivingCost that accepts  three input double data type parameters drivenMiles,  milesPerGallon, and dollarsPerGallon and returns  the dollar cost to drive those miles .
  • Calculate total dollar cost and store in the variable, dollarCost .
  • Prompt and read the miles and dollars per gallon  as input from the user .
  • Call the DrivingCost function three times  for the output to the gas cost for 10 miles,  50 miles, and 400 miles.

 

4 0
3 years ago
Read 2 more answers
Other questions:
  • Write a function named replace_at_index that takes a string and an integer. The function should return a new string that is the
    5·1 answer
  • If an interest inventory reveals that you are highly interested in solitary, introverted work, what might be the best type of ca
    9·2 answers
  • A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime be
    11·1 answer
  • Assume that you have created a class named DemoCar. Within the Main() method of this class, you instantiate a Car object named m
    12·1 answer
  • Which file system is designed to verify and autocorrect data faults on the volume without having to bring the volume down for ma
    11·1 answer
  • What is the text that is entered into a cell used to identify the purpose of the worksheet, columns, and rows? a. date and time
    14·1 answer
  • . Define the process of Technological relationship
    12·1 answer
  • Which of the following statements about wide area networks are true? Select 3 options.
    11·1 answer
  • How do you get lugia in pokemon alpha saphire
    6·1 answer
  • Consider sending a stream of packets from host a to host b using ipsec. typically, a new sa will be established for each packet
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!