Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Using Python) ******show all your codes and test it You have been hired by a sm

ID: 3771705 • Letter: #

Question

(Using Python) ******show all your codes and test it

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

import string
# define our simple thesaurus
thesaurus = {
               "happy": "glad",
               "sad" : "bleak"
             }


#inputphrase = "Happy Birthday! exclaimed the sad, sad kitten";
inputphrase= input ("Please enter a phrase:")
userphrase = inputphrase
for c in string.punctuation:
userphrase= userphrase.replace(c,"")

changedphrase = ""
for word in userphrase.split():
    if word.lower() in thesaurus.keys():
        changedphrase = changedphrase + (thesaurus[word.lower()].upper())+" "
    else:
        changedphrase = changedphrase +(word)+" "

print(changedphrase)

--output--

C:UsersRavi>python D:/ravi/Cheg/python-dictionaryReplace.txt
File "D:/ravi/Cheg/python-dictionaryReplace.txt", line 10
    inputphrase= input ("Please enter a phrase:")
    ^
IndentationError: unexpected indent

C:UsersRavi>python D:/ravi/Cheg/python-dictionaryReplace.txt
Please enter a phrase:Happy Birthday! exclaimed the sad, sad kitten
GLAD Birthday exclaimed the BLEAK BLEAK kitten