Question: please help me to fix this in python. this is my code: def countNames(l): d={} for i in range(len(l)): names=l[i].split() if len(names)==2: if names[0] in
please help me to fix this in python.

![def countNames(l): d={} for i in range(len(l)): names=l[i].split() if len(names)==2: if names[0]](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4627d2eaca_02866f4627cbc843.jpg)
this is my code:
def countNames(l): d={} for i in range(len(l)): names=l[i].split() if len(names)==2: if names[0] in d: d[names[0]].append(names[1]) else: lst=[] lst.append(names[1]) d[names[0]]=lst return d def compute_grade(file_name): overall_grade = 0 total_weight = 0 try: with open(file_name) as f: for line in f: line_list = line.split(',') grade = 0 for i in range(0, len(line_list) - 2): grade += int(line_list[i]) grade = float(grade / (len(line_list) - 2)) grade *= float(line_list[-1]) total_weight += float(line_list[-1]) overall_grade += grade overall_grade /= total_weight except: return "File not found" return overall_grade
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(): input=("Would you like to (a)dd words to the dictionary, (d)e-slang a sentence, or (q)uit?") while(input=='a'): choice=input("Enter a file name") update_dictionary(choice,d) main()
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 (a)dd 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, (d)e-slang a sentence, or (qjuit?: d Enter a sentence Enter a sentence Enter a sentence: David, y r u 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 Answer: (penalty regime 0 %)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
