Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

expected output

image text in transcribed

I got

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the chemical properties of acids with examples.

Answered: 1 week ago

Question

Write the properties of Group theory.

Answered: 1 week ago