We appreciate your visit to 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. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!

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.

Example:
If the input is:
```
automobile car
manufacturer maker
children kids
```
The sentence is:
```
The automobile manufacturer recommends car seats for children if the automobile doesn't already have one.
```

The program should output the modified sentence with the words replaced.

Answer :

Answer:

In Python:

toreplace = input("Word and replacement: ")

sentence = input("Sentence: ")

wordsplit = toreplace.split(" ")

for i in range(0,len(wordsplit),2):

sentence = sentence.replace(wordsplit[i], wordsplit[i+1])

print(sentence)

Explanation:

This gets each word and replacement from the user

toreplace = input("Word and replacement: ")

This gets the sentence from the user

sentence = input("Sentence: ")

This splits the word and replacement using split()

wordsplit = toreplace.split(" ")

This iterates through the split words

for i in range(0,len(wordsplit),2):

Each word is then replaced by its replacement in the sentence

sentence = sentence.replace(wordsplit[i], wordsplit[i+1])

This prints the new sentence

print(sentence)

Thanks for taking the time to read 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. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!

Rewritten by : Barada