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
Colt1911 [192]
4 years ago
12

Write a program that replaces words in a sentence. The input begins with word replacement pairs (original and replacement). The

next line of input is the sentence where any word on the original list is replaced.

Computers and Technology
2 answers:
Aloiza [94]4 years ago
7 0

Answer:

sentence=input("Enter a sentence:")

lis= sentence.split();

print(lis)

word=input("Enter the word to replace:")

word1=input("Enter the word to be replaced:")

i=0

for i in range(0, len(lis)):

   if lis[i]==word:

       lis[i]=word1

       i+=1

   else:

       i+=1

       continue

print("Sentence after replacement is")

print(*lis)

Explanation:

The code is as above. We here are splitting the sentence and storing in a list. And then we are replacing the word, and finally printing the sentence with replaced word.

alukav5142 [94]4 years ago
6 0

Answer:

This program is written in C++ language using Dev C++. The explanation of code is given below:

Explanation:

#include<iostream>

#include <bits/stdc++.h>

using namespace std;

 

int main()

{

   string str;// user enter sentence

   string find;//find word in sentence

   string replace;//replace word in sentence

   cout<<"Enter Sentence\n";

   getline(cin, str);//user enter sentence

   cout<<"\n Now enter key to find in sentence\n";

   getline(cin,find);//user enter "word" to find in sentence

   int findSize=(int)find.size();

   cout<<"\nNow enter a replacing word\n";

   getline(cin,replace);//user enter "word" to replace in sentence

cout << "\nOriginal text: " << str;//show original sentence

       for (int j = 0; j < (int)str.size(); j++) {//loop  

           string key = str.substr(j, findSize), repl; //search in sentence

           if (key == find) {//if find

               repl = replace;//replace

               for (int k = 0; k < findSize+2; k++) {//append

                   str[j+k] = repl[k];// new sentence

               }

           }

       }

      cout <<"\nNew text: " << str << endl;

   

   return 0;

}

You might be interested in
What should I put on a college application?⊕
gizmo_the_mogwai [7]

Answer:

Student Government. ...

Academic Teams and Clubs. ...

The Debate Team. ...

The Arts. ...

Internships. ...

Culture Clubs. ...

Volunteer Work and Community Service. ...

The Student Newspaper.

Explanation:

8 0
4 years ago
PLEASE HELP ME! Sam was researching rocks and minerals. He thought the Web site looked unprofessional, so he looked for the auth
tiny-mole [99]

Answer:

B

Explanation:

If a site looks unprofessional and doesn't have any credentials, those are two signs that it's probably not very reliable.

7 0
3 years ago
Which of these is not considered by economists to be a want?
KATRIN_1 [288]
Bowl of cereal these is not considered by economists
4 0
3 years ago
Questions 6 - 9 Refer to the following code: public class WhatsIt { private int[] values; private double average; public WhatsIt
gavmur [86]

Answer:

class WhatsIt

{

private static int [] values;

private double average;

public Double Average=average;

public WhatsIt () {values = new int [10]; findAvg(); }

public WhatsIt (int [] n) {values = n; findAvg(); }

public static void findAvg ()

{double sum = 0;

for (int i = 0; i < values.length; i++)

{sum += values[i]; }

average = 1.0 * sum / values.length;

System.out.println(Average);

System.out.println(average);

}

public static String ToString()

{

   System.out.println(average); System.out.println(values.length);

   return "Average: " + average + " Length: " + values.length;

}

public static void main(String[] args)  

{

    //WhatsIt();

    //ToString();

    findAvg();

}

}

The findAvg() calculates the average.

The reference to average is defined as below:

public double Average=average;

And when we call findAvg average is initialized, and Average is also initialized, which we can check through println statement.

Explanation:

Please check the answer section.

4 0
4 years ago
Organic farming grows more food than chemical farming true or false?
Studentka2010 [4]

FALSE

Organic farming systems yield approximately 10-20% lesser than chemical farming.

Conventional farming has always prioritized more produce, risking other sustainability metrics such as nutritional quality, energy use, soil quality, biodiversity and pollution. Organic farming presents a more balanced approach to agriculture. Organic farming better harmonizes the four areas of sustainability: environment, economics and social well-being.


6 0
3 years ago
Read 2 more answers
Other questions:
  • Show the contents of a queue after the following operations are performed. Assume the queue is initially empty. enqueue(45); enq
    6·1 answer
  • Which of these jobs would be most appropriate for someone who majors in computer engineering? I need the answer ASAP Helping com
    14·2 answers
  • Describe mobile computing
    7·1 answer
  • I need help please!!?
    11·2 answers
  • User-system interaction is?
    11·1 answer
  • What are three reasons teens might start drinking alcohol??
    7·2 answers
  • If you need to set up direct deposit, which information from your check would you likely need?
    7·2 answers
  • The primary purpose of an operating system is: To provide a software interface between the hardware and the application programs
    11·1 answer
  • What is the unit of measure ment to easure cpu speed
    11·1 answer
  • Multiple Choice
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!