Using Python You have been hired by a small software company to create a \"thesa
ID: 3769822 • Letter: U
Question
Using Python
You have been hired by a small software company to create a "thesaurus" program that replaces words with their synonyms. The company has set you up with a sample thesaurus stored in a Python dictionary object. Here's the code that represents the thesaurus:
The dictionary contains two keys - "happy" and "sad". Each of these keys holds a single synonym for that key.
Write a program that asks the user for a phrase. Then compare the words in that phrase to the keys in the thesaurus. If the key can be found you should replace the original word with a random synonym for that word. Words that are changed in this way should be printed in UPPERCASE letters. Make sure to remove all punctuation from your initial phrase so that you can find all possible matches. Here's a sample running of your program:
Explanation / Answer
input_phrase = raw_input("Enter a phrase")
print input_words
thesaurus = {'happy': 'glad', 'sad' : 'bleak'}
if input_words in thesaurus.keys():
print(" %s: %s" % (input_words, upper(thesaurus[input_words])))
else:
print " Bye!"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.