Homework 4 - the Word Counter
Exercise 4 will give you an opportunity to exercise what you know about files, functions, and lists/dictionaries. Your program should ask the user for the name of a file (located in the same directory as your program). The file will contain an arbitrary amount of text with all punctuation removed, one word per line. For instance, the file *might* contain the following text:
Four
score
and
seven
years
ago
our
fathers
brought
forth
on
this
continent
a
new
nation
conceived
in
liberty
and
to
the
proposition
that
all
men
are
created
equal
Your program should count how many times each word appears and display the most frequently occurring word, along with how many times it occurs. For instance, here is how it might interact with the user:
Enter the name of the file: gettysburg.txt
The most frequent word is and occuring 2 times
You must start your program out with a function called main(), and a function call to main() that looks like this:
def main():
fileName = input("Enter the name of the file: ")
loadWords(fileName)
[mstfrqWrd,mstfrqCnt] = findMostFrequentWord()
print("The most frequent word is", mstfrqWrd, "occuring", mstfrqCnt, "times")
return
main()