Question: using python 3: i always rate my answer. the program need a main function. i have a program here with an answer but the output

using python 3: i always rate my answer. the program need a main function. i have a program here with an answer but the output only give me the word and the frequency of the first line. i have an exmple below of both my code and mypaper.txt...Thanks!

here is my code:

def wordCount(filename): dict = {} file = open(filename, 'r') for line in file: #remove punctuations line = line.replace('.','').replace('\'','').replace(',','').lower().strip().split(' ') for word in line: if word not in dict.keys(): dict[word]=1 else: dict[word]=dict[word]+1 return dict #return dictionary def main(): filename=input('Enter the file name: ') #reading file mydict=wordCount(filename) print() print("{: >12} {: >10}".format('Word','Frequency')) print(" ==================") for key, value in sorted(mydict.items()): print("{: >12} {: >10}".format(key, value)) main()

suppose myPaper.txt is:

he body paragraphs are where you go into the greatest detail as far as facts; and evidence are concerned. When there are only two body paragraphs in an essay; you only have two main points to make. Never have more than one main point per paragraph. You can have more than; one minor point in each paragraph and particularly if they give strong support; to your main point you will use all of them.;

Because you have a specific requirement with your essay, that is you are; required to write only two fact or body paragraphs, the pressure is on to; focus precisely on the topic. The topic can only be developed or the question; in the topic can only be answered with two main points. You will not be; successful in your essay writing if you go for too many main points.;

All of this is sorted out in your outline. In your introduction you present; your thesis statement and then you develop this thesis statement with two; main points in the two body paragraphs. You sum up everything in the conclusion.

Program 4: Word Frequencies (20 pts) 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file reads from their text file NOTE: (do NOT use redirection, but rather write your program so that it ONLY works if it reads from the file whose name was entered by the user. 3. Your program will produce a dictionary of words with the number of times each occurs. The keys will be the words, and the values will be the number of times each word occurs in the text. The report should be an ALPHABETIZED output table, listing the word and the number of occurrences. NOTES: The input sequence can be words, numbers or any other immutable Python object, suitable for a dict key. Ignore case - apple is the same as Apple is the same as APPLE, etc The program could read a line of input from the file, discard all punctuation and break the line into separate words . Put the words into a dict. The first time a word is seen, the frequency is 1. Each time the word is seen again, increment the frequency. NOTE: you are REQUIRED to use the dictionary class for this assignment. Produce a frequency table. To alphabetize the frequency table, extract just the keys and sort them. This sorted sequence of keys can be used to extract the counts from the dict Make sure that your output (the table) is formatted so that the columns are aligned, and so that there are titles for each column Be sure to modularize your code , using functions appropriately. Your main program should be clean and easy to read, calling the functions with meaningful names. Pass parameters - do not use global variables. Be sure to avoid using global variables

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!