(Using Python) You are tasked with creating a dictionary program that replaces w
ID: 3771660 • Letter: #
Question
(Using Python)
You are tasked with creating a dictionary program that replaces words with synonyms! You are provided with a thesaurus that accepts one key, and has a list of possible synonyms. In fact, some famous recording artists have come to you to help them re-write some of their most popular songs so that they aren't so "repetitive". Your first customer is Mr. Justin Bieber, who's hit song "Baby" needs a little bit of work:
The lyrics to this song is stored in a text file named "bieber_baby.txt" which you can download here: bieber_baby.txt
Justin doesn't want you to change ALL of his lyrics - just a few here and there to add some variety. Begin by asking the user for a "chance" value - this value dictates the % chance that a given word will be substituted with one in the thesaurus. Finally, open the file and swap out words using the "chance" value supplied (i.e. the word is "happy" and the chance is 0.5 - this word is in the thesauraus, so there is a 50% chance that we would swap it with a random word from the thesaurus and a 50% chance that we will leave it as-is). Words that are swapped should be printed in all UPPERCASE letters. Here's a sample running of your program (note that you can simply remove all puntuation from the source file for this program):
Explanation / Answer
The following python program replaces words by their synonyms:
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.