0

HI guys, I am having some trouble with some basic python. I need to make a function that reads a document and divides each sentence up and counts the lenght of the largest sentence. this is what i have so far


def linesize(F):
c= 0
W= open("file.txt")
X= W.read()
Xlines = X.split(".")
wordcount = len(Xlines)
print wordcount


this divides up the text into sentences but them it just adds them all up at the end.. any help would be appreciated. thank you guys

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by masterofpuppets
0

hi
First, pls next time put code tags around your code :)
As for the program:

def lineSize():
    f = open( "filename.txt", "r" )
    lines = f.read()
    f.close()
    longestSentence = 0
    sentences = lines.split( "." )
    for sentence in sentences:
        if len( sentence ) > longestSentence:
            longestSentence = len( sentence )

    print longestSentence

lineSize()

This is a way of doing that. You'll probably have to deal with the \n and the punctuation as well :) Hope that helps!

Edited by masterofpuppets: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.