Question: Please create a function named makeYoung that accepts two arguments. IN PYTHON The name of a text file. This file will contain three paragraphs that
Please create a function named makeYoung that accepts two arguments. IN PYTHON
-
The name of a text file. This file will contain three paragraphs that describe happenings with various animals.
-
The name of a text file. This file will contain two columns of text, separated by tabs. The first column indicates the adult name of an animal (for example, "dog"). The second column indicates the term used to describe babies of that animal (for example, "puppy").
Your function should read the first file and look for instances of the adult animal names listed in the second file. When you find one of these adult names, you should replace it with the corresponding baby name. Finally, your function should return the modified version of the text.
Test code (to be executed after your solution):
print(makeYoung("file1.txt", "file2.txt")) EXP OUTPUT:
Once upon a time, a little puppy walked into a beautiful meadow in the mountains. She was so happy to bask in the sunshine and frolic in the flowers. Along came a kitten. Normally, a kitten does not get along with a puppy. But this time they had a grand time, smelling flowers, chasing rabbits, and digging holes. Soon the kitten and puppy lost track of time and had lost their way. Fortunately, a lamb came along and gave them directions to return to the meadow where they had been. But on their way back, they encountered a cub. The cub was quite hungry and was looking for some kind of mammal to feed to her children. The kitten and puppy scurried away as quickly as they could, and the cub was forced to compete with a cub for whatever scarce resources they could find. Moral of the story: if you are a puppy, don't play with a kitten.
File Contents:
1.
Once upon a time, a little dog walked into a beautiful meadow in the mountains. She was so happy to bask in the sunshine and frolic in the flowers. Along came a cat. Normally, a cat does not get along with a dog. But this time they had a grand time, smelling flowers, chasing rabbits, and digging holes. Soon the cat and dog lost track of time and had lost their way. Fortunately, a sheep came along and gave them directions to return to the meadow where they had been. But on their way back, they encountered a bear. The bear was quite hungry and was looking for some kind of mammal to feed to her children. The cat and dog scurried away as quickly as they could, and the bear was forced to compete with a lion for whatever scarce resources they could find. Moral of the story: if you are a dog, don't play with a cat.
2.
dog puppy sheep lamb cat kitten bear cub lion cub
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
