QuestionQuestion

Rumor has it that the literary classic Green Eggs and Ham was written because Dr. Seuss's publisher bet him he couldn't write a book using only 50 words. Write a Python program that opens the file Eggs.txt (containing the entire text of Green Eggs and Ham) and verifies this urban legend by doing the following:

* Create a count of how many total words appear in Green Eggs and Ham
* Create a count of how often each of the words appears (note that Eggs eggs Eggs! eggs? and eggs, should all be counted as the same word).
* Print out the total count and the count for each of the words.
* Print out the most commonly occuring word in the book

Note that while this problem does use files, it also uses a variety of other Python structures including strings, list and dictionary.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

print("Reading "+FILE+"\n")

# Open file
f = open(FILE)
d = {}
# Iterate through each line of file
for line in f:
    # Format line
    line = line.strip()
    if len(line) == 0:
       continue
    line = line.replace('-',' ')
    # Format each word on line
    for word in line.split(' '):
       word = word.lower()
       for p in string.punctuation:
            word = word.replace(p,'')
       # Update dictionary with word
       if word not in d:
            d[word] = 1
       else:
            d[word] += 1
# Close file
f.close()...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$50.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats