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.
pakiali007 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
pakiali007 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
hughesadam_87 54 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.