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. Ex: If the input is: automobile car manufacturer maker children kids The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. the output is: The car maker recommends car seats for kids if the car doesn't already have one. You can assume the original words are unique. 247772.1992070.q3zay7 LAB 6.19.1: LAB: Replacement words 0/ 10 АCTIVITY main.py Load default template. 1 #Define main() function 2 3 def main(): 4 #Read data from the user 6 replace_pairs = input() 7

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

6.19 LAB: Replacement words

 

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.

Ex: If the input is:

automobile car manufacturer maker children kids The automobile manufacturer recommends car seats for children if the automobile doesn't already have one.

the output is:

The car maker recommends car seats for kids if the car doesn't already have one.

You can assume the original words are unique.

 

The code I have is this but I can't find out how to make a new line.. 

 

#Define main() function

def main():

#Read data from the user

replace_pairs = input()

#Split replacement pairs into list

replace_pairs = replace_pairs.split()

#Create two lists for original and replacement words

originalWord = []

replacementWord = []

#Iterate through replacement pairs

for i in range(len(replace_pairs)):

#If it is even place

if i % 2 == 0:

#Append current item to original

originalWord.append(replace_pairs[i])

#Otherwise

else:

#append current item to replacement

replacementWord.append(replace_pairs[i])

#Read input sentence

inputSentence = input()

#Split sentence into list

inputSentence = inputSentence.split()

#Create a loop

for i in range(len(inputSentence)):

#Iterate through original list

for j in range(len(originalWord)):

#if current item in sentence matches to any item in original list

if(inputSentence[i] == originalWord[j]):

'''Replace current item in sentence by an item in

replacement which corresponds to item in original'''

inputSentence[i] = replacementWord[j]

#Print output

for i in range(len(inputSentence)):

print(inputSentence[i], end = " ")

#Call main() function

if __name__=="__main__":

main()

< >
learn.zybooks.com
b Answered: In Python, Write a pr...
ży Section 6.19 - IT 140: Introducti...
B Grades - IT-140-J6169 Introdu...
* Set 8.pdf :COSC 1306 : Univer...
Tinder | Dating, Make Friends &...
Snapchat - The fastest way t ..
= zyBooks My library > IT 140: Introduction to Scripting v3 home > 6.19: LAB: Replacement words
E zyBooks catalog
2 Help/FAQ
8 Victoria Thibodeaux
Submit for grading
Signature of your work
What is this?
8/4.. W-|0 | 0|0|0|0|0 ..8/4
Latest submission - 1:55 AM EDT on 08/04/21
Total score: 0 / 10
Only show failing tests
Download this submission
1: Compare output a
0/4
Output is nearly correct; but whitespace differs. See highlights below.
Special character legend
automobile car
manufacturer maker
children kids
Input
The automobile manufacturer recommends car seats for children if the aut
Your output aker recommends car seats for kids if the car doesn't already have one.
Expected output aker recommends car seats for kids if the car doesn't already have one.
2: Compare output ^
0/3
Output is nearly correct; but whitespace differs. See highlights below.
Special character legend
class course
greatest best
Input
My CS class is the greatest class I have ever taken!
Your output
My CS course is the best course I have ever taken!
Exnected outnut
My
is the best
have
taken!
Course
Course
ever
Transcribed Image Text:< > learn.zybooks.com b Answered: In Python, Write a pr... ży Section 6.19 - IT 140: Introducti... B Grades - IT-140-J6169 Introdu... * Set 8.pdf :COSC 1306 : Univer... Tinder | Dating, Make Friends &... Snapchat - The fastest way t .. = zyBooks My library > IT 140: Introduction to Scripting v3 home > 6.19: LAB: Replacement words E zyBooks catalog 2 Help/FAQ 8 Victoria Thibodeaux Submit for grading Signature of your work What is this? 8/4.. W-|0 | 0|0|0|0|0 ..8/4 Latest submission - 1:55 AM EDT on 08/04/21 Total score: 0 / 10 Only show failing tests Download this submission 1: Compare output a 0/4 Output is nearly correct; but whitespace differs. See highlights below. Special character legend automobile car manufacturer maker children kids Input The automobile manufacturer recommends car seats for children if the aut Your output aker recommends car seats for kids if the car doesn't already have one. Expected output aker recommends car seats for kids if the car doesn't already have one. 2: Compare output ^ 0/3 Output is nearly correct; but whitespace differs. See highlights below. Special character legend class course greatest best Input My CS class is the greatest class I have ever taken! Your output My CS course is the best course I have ever taken! Exnected outnut My is the best have taken! Course Course ever
learn.zybooks.com
b Answered: In Python, Write a pr...
ży Section 6.19 - IT 140: Introducti...
B Grades - IT-140-J6169 Introdu...
* Set 8.pdf :COSC 1306 : Univer...
Tinder | Dating, Make Friends &...
Snapchat - The fastest way to s...
= zyBooks My library > IT 140: Introduction to Scripting v3 home > 6.19: LAB: Replacement words
B zyBooks catalog
? Help/FAQ e Victoria Thibodeaux
16.18 LAB: Word frequencies
6.19 LAB: Replacement words
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.
Ex: If the input is:
automobile car
manufacturer maker
children kids
The automobile manufacturer recommends car seats for children if the automobile doesn't already
have one.
the output is:
The car maker recommends car seats for kids if the car doesn't already have one.
You can assume the original words are unique.
247772.1992070.qx3zqy7
LAB
6.19.1: LAB: Replacement words
0/ 10
АCTIVITY
main.py
Load default template...
1 #Define main() function
2
3 def main():
4
5
#Read data from the user
6.
7
replace_pairs
input()
=
Transcribed Image Text:learn.zybooks.com b Answered: In Python, Write a pr... ży Section 6.19 - IT 140: Introducti... B Grades - IT-140-J6169 Introdu... * Set 8.pdf :COSC 1306 : Univer... Tinder | Dating, Make Friends &... Snapchat - The fastest way to s... = zyBooks My library > IT 140: Introduction to Scripting v3 home > 6.19: LAB: Replacement words B zyBooks catalog ? Help/FAQ e Victoria Thibodeaux 16.18 LAB: Word frequencies 6.19 LAB: Replacement words 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. Ex: If the input is: automobile car manufacturer maker children kids The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. the output is: The car maker recommends car seats for kids if the car doesn't already have one. You can assume the original words are unique. 247772.1992070.qx3zqy7 LAB 6.19.1: LAB: Replacement words 0/ 10 АCTIVITY main.py Load default template... 1 #Define main() function 2 3 def main(): 4 5 #Read data from the user 6. 7 replace_pairs input() =
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Parallel Processing
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education