Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Reads the file with filename into your function and returns the longest word in the text file. - Words are separated by whitespace characters,

Hello,

Reads the file with filename into your function and returns the longest word in the text file. - Words are separated by whitespace characters, but does not include the following punctuation characters (,.!?;). You can assume contractions count as one word (i.e. "don't", "you'll", etc. are one word). - In the case of a tie, the 1st occurrence of the longest word is returned. - The split and strip functions may be useful. - Your function should open the file for reading, and close the file before returning.

I have below this code but cannot seem to pass the test functions. image text in transcribed

def longestWord(filename): maxword = '' with open(filename, 'r') as x: for line inx: linelist line.splitO word in linelist: if len(word) len(maxword): maxword -word return maxword

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

LO5 Illustrate the steps in developing a base pay system.

Answered: 1 week ago

Question

LO3 Outline strategic compensation decisions.

Answered: 1 week ago