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...



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()




< ><br>learn.zybooks.com<br>b Answered: In Python, Write a pr...<br>ży Section 6.19 - IT 140: Introducti...<br>B Grades - IT-140-J6169 Introdu...<br>* Set 8.pdf :COSC 1306 : Univer...<br>Tinder | Dating, Make Friends &...<br>Snapchat - The fastest way t ..<br>= zyBooks My library > IT 140: Introduction to Scripting v3 home > 6.19: LAB: Replacement words<br>E zyBooks catalog<br>2 Help/FAQ<br>8 Victoria Thibodeaux<br>Submit for grading<br>Signature of your work<br>What is this?<br>8/4.. W-|0 | 0|0|0|0|0 ..8/4<br>Latest submission - 1:55 AM EDT on 08/04/21<br>Total score: 0 / 10<br>Only show failing tests<br>Download this submission<br>1: Compare output a<br>0/4<br>Output is nearly correct; but whitespace differs. See highlights below.<br>Special character legend<br>automobile car<br>manufacturer maker<br>children kids<br>Input<br>The automobile manufacturer recommends car seats for children if the aut<br>Your output aker recommends car seats for kids if the car doesn't already have one.<br>Expected output aker recommends car seats for kids if the car doesn't already have one.<br>2: Compare output ^<br>0/3<br>Output is nearly correct; but whitespace differs. See highlights below.<br>Special character legend<br>class course<br>greatest best<br>Input<br>My CS class is the greatest class I have ever taken!<br>Your output<br>My CS course is the best course I have ever taken!<br>Exnected outnut<br>My<br>is the best<br>have<br>taken!<br>Course<br>Course<br>ever<br>

Extracted 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<br>b Answered: In Python, Write a pr...<br>ży Section 6.19 - IT 140: Introducti...<br>B Grades - IT-140-J6169 Introdu...<br>* Set 8.pdf :COSC 1306 : Univer...<br>Tinder | Dating, Make Friends &...<br>Snapchat - The fastest way to s...<br>= zyBooks My library > IT 140: Introduction to Scripting v3 home > 6.19: LAB: Replacement words<br>B zyBooks catalog<br>? Help/FAQ e Victoria Thibodeaux<br>16.18 LAB: Word frequencies<br>6.19 LAB: Replacement words<br>Write a program that replaces words in a sentence. The input begins with word replacement pairs (original and replacement). The next line<br>of input is the sentence where any word on the original list is replaced.<br>Ex: If the input is:<br>automobile car<br>manufacturer maker<br>children kids<br>The automobile manufacturer recommends car seats for children if the automobile doesn't already<br>have one.<br>the output is:<br>The car maker recommends car seats for kids if the car doesn't already have one.<br>You can assume the original words are unique.<br>247772.1992070.qx3zqy7<br>LAB<br>6.19.1: LAB: Replacement words<br>0/ 10<br>АCTIVITY<br>main.py<br>Load default template...<br>1 #Define main() function<br>2<br>3 def main():<br>4<br>5<br>#Read data from the user<br>6.<br>7<br>replace_pairs<br>input()<br>=<br>

Extracted 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() =
Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here