Question: expected output I got here is my code def update_dictionary(filename, d): try: with open(filename, 'r') as f: print(filename + ' loaded successfully.') for line in

 expected output I got here is my code def update_dictionary(filename, d):

expected output

try: with open(filename, 'r') as f: print(filename + ' loaded successfully.') for

I got

line in f: words = line.strip().split(",") d[words[0]] = words[1] except: print(filename +

here is my code

def update_dictionary(filename, d): try: with open(filename, 'r') as f: print(filename + ' loaded successfully.') for line in f: words = line.strip().split(",") d[words[0]] = words[1] except: print(filename + ' does not exist.') print('The dictionary has ' + str(len(d.items())) + ' entries.') return d

def deslang(slang, d): deslanged = [] for word in slang.split(): if word in d: deslanged.append(d[word]) else: deslanged.append(word) return ' '.join(deslanged)

def main(): words = {} userInput = input('Would you like to (a)dd words to the dictionary, (d)e-slang a sentence, or (q)uit?: ') while (userInput != 'q'): if userInput == 'a': file_name = input("Enter a filename: ") update_dictionary(file_name, words) if userInput == 'd': sentence = input('Enter a sentence: ') while sentence.strip() == '': sentence = input('Enter a sentence: ') sentence = deslang(sentence, words) print(sentence) if userInput != 'q': userInput = input('Would you like to (a)dd words to the dictionary, (d)e-slang a sentence, or (q)uit?: ')

main()

tell me how to modify only the main function ,thanks!!

Your main function in the py file containing your functions, update_dictionary, and deslang, should provide the following menu: Would you like to (a)dd words to the dictionary, (d)e-slang a sentence, or (q)uit? For this assignment, will be testing your code by running your entire file (as we did in Homework 7). Please reference the following sample runs for your menu functionality: Would you like to (aldd words to the dictionary, (d)e-slang a sentence, or (q)uit?: a Enter a filename: textToEnglish.txt textToEnglish.txt loaded successfully. The dictionary has 4239 entries. Would you like to (a)dd words to the dictionary, (dje-slang a sentence, or (quit?: d Enter a sentence: Enter a sentence: Enter a sentence: David, yr u l8 David, why are you late Would you like to (a)dd words to the dictionary, (d)e-slang a sentence, or (q)uit?: q Copy your solution to the previous questions(Q1 and Q2) here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!