Python Character Analysis And Letter Frequency Programming Assignment


PYTHON homework. The instruction and the files to test the program are attached.

Character Analysis – Letter Frequency:
You are going to analyze the usage of different characters in a text file by counting the number of
occurrences of each character and storing them in a Dictionary. This process begins by creating a Set of
the characters contained in the String. Remember that a Set is an unordered sequence that contains no
duplicate values.
Example input text:
“This is an example of a small data file with only one sentence.”
A Set of all characters contained in this sentence:
{‘h’, ‘d’, ‘e’, ‘t’, ‘s’, ‘.’, ‘l’, ‘p’, ‘f’, ‘T’, ‘x’, ‘i’, ‘a’, ‘n’, ‘o’,
‘m’, ‘c’, ‘w’, ‘ ‘}
The entries in the Set can be used as keys in a Dictionary and the number of occurrences of each Set
entry will be the corresponding Dictionary value. Since ‘h’ occurs twice in the String — so the Dictionary
key ‘h’ will have a value of 2. If a Dictionary is named myDict then:
myDict[‘h’] = 2
The Assignment
Write a program named that prompts the user for a filename to evaluate, reads the
contents of the file and displays an alphabetical analysis of the number of occurrences of each character
contained in the file. You’re provided with several files that you can use to test your Python program. It
should work correctly with all of them.
TO DO #1: Setup your program and main() function
As with all assignments, your program should have an appropriate header including your name, the
program name and a description of it’s functionality. In addition, define the main() function to display a
program description to the user and prompt for a filename to process.

Define a header with comments including your name, the program’s name and a description of
the program’s function

Define a main() function that displays a message describing the purpose of the program

Prompt the user for the file name containing the text to be processed
TO DO #2: Define the readFile() function
The readFile() function should accept one argument (a filename as a String) and should return two
values (a String and a Set). The String returned contains the contents of the text file. The Set returned
contains all the characters in the text file with no duplicates.

Define the readFile() function to accept one argument, a String

Open the text file using the file name String provided as an argument

Read the contents of the text file into a new String

Close the text file

Create a Set containing all the unique characters in the String read from the text file

Return the the text from the file as a String and the Set of unique characters.
1 of 2
TO DO #3: Define the catalog() function
The catalog() function should accept two arguments (a String and a Set) and returns a Dictionary.
The String and Set arguments were created by the readFile() function and contain the data from the
text file and the Set of unique characters. The catalog() function creates and returns a Dictionary
containing the number of occurrences of each character in the Set.

Define the catalog() function that accepts two arguments, a String and a Set

Create a Dictionary using the entries in the Set as keys and the number of occurrences for each
entry in the String as values (see example in assignment description above).

The catalog() function should return the new Dictionary
TO DO #4: Modify the main() function

Modify the main() function to display the message, ‘Reading data file…’

Modify the main() function to call readFile() providing the file name as an
argument. (Remember to assign the String and Set returned by readFile() to

Modify the main() function to display the message, ‘Analyzing data

Modify the main() function to call catalog() providing the String and Set as
arguments (Remember to assign the Dictionary returned by catalog() to a

Modify the main() function to display the message, ‘Printing analysis

Print the key – value pairs from the Dictionary. An example of the pairs are shown
here. Your values and the order of characters will vary.
2 of 2
Four score and seven years ago our fathers brought forth on this continent, a new
nation, conceived in Liberty, and dedicated to the proposition that all men are
created equal.
Now we are engaged in a great civil war, testing whether that nation, or any nation
so conceived and dedicated, can long endure. We are met on a great battle-field of
that war. We have come to dedicate a portion of that field, as a final resting
place for those who here gave their lives that that nation might live. It is
altogether fitting and proper that we should do this.
But, in a larger sense, we can not dedicate — we can not consecrate — we can not
hallow — this ground. The brave men, living and dead, who struggled here, have
consecrated it, far above our poor power to add or detract. The world will little
note, nor long remember what we say here, but it can never forget what they did
here. It is for us the living, rather, to be dedicated here to the unfinished work
which they who fought here have thus far so nobly advanced. It is rather for us to
be here dedicated to the great task remaining before us — that from these honored
dead we take increased devotion to that cause for which they gave the last full
measure of devotion — that we here highly resolve that these dead shall not have
died in vain — that this nation, under God, shall have a new birth of freedom -and that government of the people, by the people, for the people, shall not perish
from the earth.
NO man thinks more highly than I do of the patriotism, as well as abilities, of the
very worthy gentlemen who have just addressed the House. But different men often
see the same subject in different lights; and, therefore, I hope that it will not
be thought disrespectful to those gentlemen, if entertaining, as I do, opinions of
a character very opposite to theirs, I shall speak forth my sentiments freely, and
without reserve. This is no time for ceremony. The question before the House is one
of awful moment to this country. For my own part, I consider it as nothing less
than a question of freedom or slavery. And in proportion to the magnitude of the
subject, ought to be the freedom of the debate. It is only in this way that we can
hope to arrive at truth and fulfill the great responsibility which we hold to God
and our country. Should I keep back my opinions at such a time, through fear of
giving offense, I should consider myself as guilty of treason towards my country
and of an act of disloyalty towards the majesty of Heaven which I revere above all
earthly kings.
Mr. President it is natural to man to indulge in the illusions of hope. We are apt
to shut our eyes against a painful truth – and listen to the song of the siren till
she transforms us into beasts. Is this the part of wise men engaged in a great and
arduous struggle for liberty? Are we disposed to be of the number of those who,
having eyes, see not, and having ears, hear not, the things which so nearly concern
their temporal salvation? For my part, whatever anguish of spirit it may cost, I
am willing to know the whole truth; to know the worst and to provide for it.
I have but one lamp by which my feet are guided; and that is the lamp of
experience. I know of no way of judging of the future but by the past. And judging
by the past, I wish to know what there has been in the conduct of the British
ministry for the last ten years to justify those hopes with which gentlemen have
been pleased to solace themselves and the house? Is it that insidious smile with
which our petition has been lately received? Trust it not, sir; it will prove a
snare to your feet. Suffer not yourselves to be betrayed with a kiss. Ask
yourselves how this gracious reception of our petition comports with these warlike
preparations which cover our waters and darken our land. Are fleets and armies
necessary to a work of love and reconciliation? Have we shown ourselves so
unwilling to be reconciled that force must be called in to win back our love? Let
us not deceive ourselves, sir. These are the implements of war and subjugation the last arguments to which kings resort.
I ask gentlemen, sir, what means this martial array if its purpose be not to force
us to submission? Can gentlemen assign any other possible motives for it? Has Great
Britain any enemy, in this quarter of the world to call for all this accumulation
of navies and armies? No, sir, she has none. They are meant for us: they can be
meant for no other. They are sent over to bind and rivet upon us those chains which
the British ministry have been so long forging.
And what have we to oppose to them? Shall we try argument? Sir, we have been trying
that for the last ten years. Have we anything new to offer on the subject? Nothing.
We have held the subject up in every light of which it is capable; but it has been
all in vain. Shall we resort to entreaty and humble supplication? What terms shall
we find which have not been already exhausted?
Let us not, I beseech you, sir, deceive ourselves longer. Sir, we have done
everything that could be done to avert the storm which is now coming on. We have
petitioned – we have remonstrated – we have supplicated – we have prostrated
ourselves before the throne, and have implored its interposition to arrest the
tyrannical hands of the ministry and Parliament. Our petitions have been slighted;
our remonstrances have produced additional violence and insult; our supplications
have been disregarded; and we have been spurned, with contempt, from the foot of
the throne.
In vain, after these things, may we indulge the fond hope of peace and
reconciliation. There is no longer any room for hope. If we wish to be free – if
we mean to preserve inviolate those inestimable privileges for which we have been
so long contending – if we mean not basely to abandon the noble struggle in which
we have been so long engaged, and which we have pledged ourselves never to abandon
until the glorious object of our contest shall be obtained – we must fight! I
repeat it, sir, we must fight! An appeal to arms and to the God of Hosts is all
that is left us!
They tell us, sir, that we are weak – unable to cope with so formidable an
adversary. But when shall we be stronger? Will it be the next week, or the next
year? Will it be when we are totally disarmed, and when a British guard shall be
stationed in every house? Shall we gather strength by irresolution and inaction?
Shall we acquire the means of effectual resistance by lying supinely on our backs,
and hugging the delusive phantom of Hope, until our enemies shall have bound us
hand and foot?
Sir, we are not weak, if we make a proper use of the means which the God of nature
hath placed in our power. Three millions of people, armed in the holy cause of
liberty, and in such a country as that which we possess, are invincible by any
force which our enemy can send against us.
Besides, sir, we shall not fight our battles alone. There is a just God who
presides over the destinies of nations, and who will raise up friends to fight our
battles for us. The battle, sir, is not to the strong alone; it is to the
vigilant, the active, the brave. Besides, sir, we have no election. If we were base
enough to desire it, it is now too late to retire from the contest. There is no
retreat, but in submission and slavery! Our chains are forged, their clanking may
be heard on the plains of Boston! The war is inevitable – and let it come! I repeat
it, sir, let it come!
It is in vain, sir, to extenuate the matter. Gentlemen may cry, peace, peace – but
there is no peace. The war is actually begun. The next gale that sweeps from the
north will bring to our ears the clash of resounding arms! Our brethren are already
in the field! Why stand we here idle? What is it that gentlemen wish? What would
they have? Is life so dear, or peace so sweet, as to be purchased at the price of
chains and slavery? Forbid it, Almighty God! I know not what course others may
take; but as for me, give me liberty, or give me death!
This is an example of a small data file with only one sentence.

Purchase answer to see full

We offer the bestcustom writing paper services. We have done this question before, we can also do it for you.

Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.