Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix this error in Python. Here was the assignment. from sys import argv def longest_ word(fn_input): file_inputopen (mary.txt, r) maxLength0 maxWord = for

image text in transcribedimage text in transcribedPlease fix this error in Python. Here was the assignment. image text in transcribed

from sys import argv def longest_ word(fn_input): file_inputopen (mary.txt, "r") maxLength0 maxWord = "" for line in file_input: for word in line.split(" "): if maxlength len (word): maxLengthlen (word) maxWord -word return maxword if _name_ "main__"; fn-in-argv [1]1 print(longest_word(fn_in)) In [17]: runfile ("/Users/Jay/Desktop/LAB/ untitled1.py', wdir- /Users/Jay/Desktop/ LAB') Traceback (most recent call last): File "", line 1, in runfile("/Users/Jay/Desktop/LAB/ untitled 1 . py. LAB') wdir-'/Users/Jay/Desktop/ File "/anaconda3/lib/python3.7/site packages/spyder_kernels/customize/ spydercustomize.py", line 704, in runfile execfile(filename, namespace) File "/anaconda3/lib/python3.7/site packages/spyder_kernels/customize/ spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec) namespace) File "/Users/Jay/Desktop/LAB/ untitled1.py", line 22, in fn inargv [1] IndexError: list index out of range 1. (10 Points) Write a program that prints the word that has the longest length, in terms of the number of characters, in the supplied text file. Show your output to the TA on the following text files: mary.txt and frost.txt

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

Step: 3

blur-text-image

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

Algorithmic Trading Navigating The Digital Frontier

Authors: Alex Thompson

1st Edition

B0CHXR6CXX, 979-8223284987

More Books

Students also viewed these Databases questions

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago