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

USING PYTHON 12- Write a function named wordLenghts, it takes two paramters: 1-i

ID: 3837030 • Letter: U

Question

USING PYTHON 12- Write a function named wordLenghts, it takes two paramters: 1-inFilea string that is the name of the input file and 2-outFile a string that is the name of the output file.The input file exits when wordLenghts is called; wordLenghts must create the file outFile. the input file contains only letters and white space. For each line of the input file , wordLenghts should identify the lenght of the longest word on the line and how many words of that lenght there are.It should write the lenght of the longest word, followed by a space, followed by how many words of that lenght there are on the line to a corresponding line in the outFile. If a line in the input file is empty the corresponding line of the output file should also be empty

Explanation / Answer

program: def main(): real_longest = [''] filename = input("What is the filename?") with open(filename) as f: linenum = 1 for line in f: words = line.split() longest = '' for word in words: if word[-1].isalpha() == False: word = word[:-1] if len(longest) len(real_longest[0]): real_longest = [longest] elif len(longest) == len(real_longest[0]): real_longest.append(longest) linenum += 1 print(longest) for word in real_longest: print('This word is one of the largest:', word)