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
larisa [96]
2 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]2 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 the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message
Oksana_A [137]

Answer:

The function definition, in cpp, for the function printAttitude is given below.

void printAttitude(int n)

{

switch(n)

{

case 1: cout<<"disagree"<<endl; break;

case 2: cout<<"no opinion"<<endl; break;

case 3: cout<<"agree"<<endl; break;

default: break;

}

}

Explanation:

As seen, the method takes an integer parameter.

The method does not returns any value hence, return type is void.

The message is displayed to the console using switch statement which executes on the integer parameter, n.

The values for which output needs to be displayed are taken in cases.

The values for which no output needs to be displayed, is taken in default case.

Every case ends with break statement so that the program execution can be terminated.

This method can be used inside a program as shown.  

PROGRAM

#include <iostream>

using namespace std;

void printAttitude(int n)

{

switch(n)

{

case 1: cout<<"disagree"<<endl; break;

case 2: cout<<"no opinion"<<endl; break;

case 3: cout<<"agree"<<endl; break;

default: break;

}

}

int main() {

// variables to hold respective value

int n;

// user input taken for n

cout<<"Enter any number: ";

cin>>n;

// calling the function taking integer parameter  

printAttitude(n);

return 0;

}

OUTPUT

Enter any number: 11

1. The user input is taken for the integer parameter.

2. Inside main(), the method, printAttitude(), is then called and the user input is passed as a parameter.

3. Since the user entered value is 11 which does not satisfies any of the values in the cases, the default case is entered which does nothing and executes the break statement.

4. Hence, the program displays nothing for the value of 11.

5. When the user enters value 3, the case statement is executed since 3 satisfies one of the case values.

6. The program output for the user input of 3 is as shown below.

OUTPUT

Enter any number: 3

agree

The program ends with return statement.

4 0
1 year ago
Which Artificial Intelligence (AI) term is used to describe extracting information from unstructured text using algorithms?
Alla [95]

Answer:

The most basic and useful technique in NLP is extracting the entities in the text. It highlights the fundamental concepts and references in the text. Named entity recognition (NER) identifies entities such as people, locations, organizations, dates, etc. from the text.

5 0
1 year ago
Peter accumulated many photos from his visit to Wisconsin. He wants to upload these photos to a social networking site. Which fi
daser333 [38]

Answer:

JPG / JPEG best choice and work well on websites

Explanation:

JPEGs contains millions of colors, so this type of file is ideal for photographs.

Best choice for posting on social media channels

7 0
2 years ago
Write a program to input value of three sides, to check triangle is triangle is possible to form of not​
NeTakaya

Answer:

Explanation:

import java.util.Scanner;

public class KboatTriangleAngle

{

  public static void main(String args[]) {

      Scanner in = new Scanner(System.in);

      System.out.print("Enter first angle: ");

      int a1 = in.nextInt();

      System.out.print("Enter second angle: ");

      int a2 = in.nextInt();

      System.out.print("Enter third angle: ");

      int a3 = in.nextInt();

      int angleSum = a1 + a2 + a3;

       

      if (angleSum == 180 && a1 > 0 && a2 > 0 && a3 > 0) {

          if (a1 < 90 && a2 < 90 && a3 < 90) {

              System.out.println("Acute-angled Triangle");

          }

          else if (a1 == 90 || a2 == 90 || a3 == 90) {

              System.out.println("Right-angled Triangle");

          }

          else {

              System.out.println("Obtuse-angled Triangle");

          }

      }

      else {

          System.out.println("Triangle not possible");

      }

  }

}

OUTPUT:

3 0
2 years ago
Nancy would like to configure an automatic response for all emails received while she is out of the office tomorrow, during busi
Stella [2.4K]

she can appoints someone she trust to act on her behalf

4 0
2 years ago
Read 2 more answers
Other questions:
  • Refer to the exhibit. pc1 issues an arp request because it needs to send a packet to pc3. in this scenario, what will happen nex
    9·1 answer
  • if you had two proxy servers located in the same room, what use could you make of them? nothing create a hub sell one of the ser
    14·2 answers
  • Olivia creates a personal budget. She enters her current savings account balance in cell D3. In cell A3, she calculates her inco
    8·1 answer
  • RFID tags are used in secure environments primarily due to the fact they are impossible to counterfeit.
    5·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    15·1 answer
  • Row array gameScores contains all player scores. Construct a row array highScores than contains all player scores greater than m
    15·1 answer
  • Server farms such as Google and Yahoo! provide enough compute capacity for the highest request rate of the day. Imagine that mos
    12·1 answer
  • _____________ data is what is translated to digital format so it can be stored in a computer.
    10·1 answer
  • Jason works as a financial investment advisor. He collects financial data from clients, processes the data online to calculate t
    14·1 answer
  • A large offshore oil platform needs to transmit signals between different devices on the platform with high reliability and low
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!