0
# This program reads numbers from a file into a list.
def main():
    # Open a file for reading.
    infile = open('text.txt', 'r')
    sentences = infile.readlines() # Read the contents of the file into a list.
    infile.close()                          # Close the file.


    index = 0                               # Convert each element to an int.
    while index < len(sentences):



        print (sentences[index], index) #PRINT EACH ELEMENT
        index += 1

        # Print the contents of the list.

    print (index)


# Call the main function.
main()
3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by Ene Uran
Featured Replies
  • Take a page containing a list of sentences, like [this one](http://ufal.mff.cuni.cz/~toman/pedt_manual/ar01.html) (take only the first 5 sentences). Then with a calculator, compute the average number of words per sentence by hand and note carefully everything you do. This should give you a working algorithm. Write pseudo code, then python code. Read More

  • Assume the sentences end with '.' or '?' or '!' so count these characters and divide the total words by the number of these characters. Read More

1

Take a page containing a list of sentences, like this one (take only the first 5 sentences). Then with a calculator, compute the average number of words per sentence by hand and note carefully everything you do. This should give you a working algorithm. Write pseudo code, then python code.

Edited by Gribouillis

1

Assume the sentences end with '.' or '?' or '!' so count these characters and divide the total words by the number of these characters.

Comments
interesting idea
This article 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.