Answer:
Step-by-step explanation:
The following code is written in Python. It is a function that takes in the name of the file to be read and the size of the word. Then the function reads the file, removes whitespace and commas, splits the text into words, and scans the words for all the words that have the same length as the number passed. It counts all those words and prints out the number of occurrences of words of that length.
def countOccurrences(file_name, word_size):
f = open(file_name, 'r')
text = f.read()
text = text.replace(',', '')
split_text = text.split(' ')
occurrences = 0
for word in split_text:
if len(word) == word_size:
occurrences += 1
print("Length 1: " + str(occurrences) + " occurrences")