0

ile problem 2.
Write a function named countTriWords() that opens a file for reading, reads each line in the file, and returns the number of three letter words in the file. For simplicity, you may ignore the fact that some characters are punctuation and treat them as part of the word they are next to.
Input (one parameter):
* filename -- name of file to open for reading
Output:
* return the number of three letter words in the file. If a word occurs more than once, each
occurrence should be counted.
For example, after creating the file FatherWilliam.txt and writing the above verse to it, the function call
countTriWords('FatherWilliam.txt')
should return the number 11, because there are 11 occurrences of three letter words in the file (You, are, old, the, man, and, has, and, yet, you, you.)
Hint 1: Use a for loop to read all the lines in the file. Hint 2: Use the string method split() to divide each line into a list of words.

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by hughesadam_87
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.