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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started