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.

Recommended Answers

All 4 Replies

You forgot to post your code and what is your problem.

thats what i need the code i don't have the code

Then you need to write it, then come here with it, if you have problem with it.

Yeah you have to put in an effort, we can't do homework for you.

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.