Question: You are going to create some Mad Libs. There are two files available: a word list full of common words (words.txt), and a short story
You are going to create some Mad Libs. There are two files available: a word list full of common words ("words.txt"), and a short story ("story.txt"). Process both files line-by-line in order to replace the words from the first file in the short story with the string "____" (four underscores). Then, print the resulting story, each line of the story on its own line.
One issue you may encounter: You cannot loop through a file again after you have read its contents once. Solve this issue by storing the words file in a list before processing the story.
In python
words.txt
cat that phat chat combat bat fat hat rat
The cat in the hat came back the other day, chasing a bat and a rat. I asked the cat in the hat why the bat and the rat were his combat. He said, "that bat and the rat said I was fat!" The bat and the rat groaned and turned to me. "We said he was phat!" they said as a plea. I calmed and spoke kindly to the cat with the hat, "Can't we make this into a nice chat?" And that was the end of that.
story.txt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
