Question

In: Computer Science

Using Python in vs code: The distribution of letters in a document has a distinctive and...

Using Python in vs code:

The distribution of letters in a document has a distinctive and predictable shape, as shown in the following figure. This distribution could be effective information to break a cipher. Write a program that reads an input file, and outputs the count or frequency of all 26 letters to an output file: count.dat. Case sensitivity is not considered, i.e., ‘a’ is treated as the same as ‘A’. Test file is “independence.txt”. In the output file, you don’t need to draw a histogram and a frequency output as in Question 5 is sufficient. A screenshot of the content of this output file should be provided.

please include screenshots of your outputs.

independence.txt is:

We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.

Article. I.
Section. 1.
All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives.

Section. 2.
The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature.

No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen.

Representatives and direct Taxes shall be apportioned among the several States which may be included within this Union, according to their respective Numbers, which shall be determined by adding to the whole Number of free Persons, including those bound to Service for a Term of Years, and excluding Indians not taxed, three fifths of all other Persons. The actual Enumeration shall be made within three Years after the first Meeting of the Congress of the United States, and within every subsequent Term of ten Years, in such Manner as they shall by Law direct. The Number of Representatives shall not exceed one for every thirty Thousand, but each State shall have at Least one Representative; and until such enumeration shall be made, the State of New Hampshire shall be entitled to chuse three, Massachusetts eight, Rhode-Island and Providence Plantations one, Connecticut five, New-York six, New Jersey four, Pennsylvania eight, Delaware one, Maryland six, Virginia ten, North Carolina five, South Carolina five, and Georgia three.

When vacancies happen in the Representation from any State, the Executive Authority thereof shall issue Writs of Election to fill such Vacancies.

The House of Representatives shall chuse their Speaker and other Officers; and shall have the sole Power of Impeachment.

Section. 3.
The Senate of the United States shall be composed of two Senators from each State, chosen by the Legislature thereof, for six Years; and each Senator shall have one Vote.

Immediately after they shall be assembled in Consequence of the first Election, they shall be divided as equally as may be into three Classes. The Seats of the Senators of the first Class shall be vacated at the Expiration of the second Year, of the second Class at the Expiration of the fourth Year, and of the third Class at the Expiration of the sixth Year, so that one third may be chosen every second Year; and if Vacancies happen by Resignation, or otherwise, during the Recess of the Legislature of any State, the Executive thereof may make temporary Appointments until the next Meeting of the Legislature, which shall then fill such Vacancies.

No Person shall be a Senator who shall not have attained to the Age of thirty Years, and been nine Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State for which he shall be chosen.

The Vice President of the United States shall be President of the Senate, but shall have no Vote, unless they be equally divided.

The Senate shall chuse their other Officers, and also a President pro tempore, in the Absence of the Vice President, or when he shall exercise the Office of President of the United States.

The Senate shall have the sole Power to try all Impeachments. When sitting for that Purpose, they shall be on Oath or Affirmation. When the President of the United States is tried, the Chief Justice shall preside: And no Person shall be convicted without the Concurrence of two thirds of the Members present.

Judgment in Cases of Impeachment shall not extend further than to removal from Office, and disqualification to hold and enjoy any Office of honor, Trust or Profit under the United States: but the Party convicted shall nevertheless be liable and subject to Indictment, Trial, Judgment and Punishment, according to Law.

Solutions

Expert Solution

Python :

import sys
import collections
import pprint
Input_file = input('Please Enter the name of the File :  ') #Input the file name
with open(Input_file, 'r') as text_content:                 #Opening the file
  total_counts = collections.Counter(text_content.read().lower())  #Counting the characters using collections module
  correspond_values = pprint.pformat(total_counts)
print(correspond_values) #prints the letter frequencies to console
Output_file=open("count.dat", "w") #open or creating COUNT.DAT/output file as writable
Output_file.write(correspond_values) #writing to the output file
Output_file.close() #closing the output file

Python Program that reads an Input file, and outputs the count or frequency of all 26 letters to an output file named as count.dat., where case sensitivity is not considered.

Screenshot of Content of Output File count.dat :

Console Output:


Related Solutions

A person has to create a code. The code must contain exactly 6 letters. The first...
A person has to create a code. The code must contain exactly 6 letters. The first letter must be a vowel that is not an E or I. The second letter must be either a J, K, or L. The third letter must be a consonant that is not a G or R. The fourth letter must be a vowel that is not an I. The fifth letter must be a consonant. If repetition of letters are not allowed, how...
A person has to create a code. The code must contain exactly 7 letters. The first...
A person has to create a code. The code must contain exactly 7 letters. The first letter must either a N, P, R, or T. The second letter must be a vowel that is not I, O, or U. The third letter must be a consonant that is not a D, F, H, or J. The fourth letter must be a vowel that is not an O or U. The fifth letter must be a consonant that is not a...
PYTHON PROGRAMMING Using tktinker, create a gui that surrounds the code below that has buttons and...
PYTHON PROGRAMMING Using tktinker, create a gui that surrounds the code below that has buttons and labels and an overall theme. # Meet the chatbot Eve print('Hi there! Welcome to the ChatBot station. I am going to ask you a series of questions and all you have to do is answer!') print(' ') print('Lets get started') #begin questions firstName = input('What is your first name?: ') lastName = input('What is your last name? ') print("Hi there, ", firstName + lastName,...
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Python Code for 8-queens using random restart algorithms
Python Code for 8-queens using random restart algorithms
Using the code letters below, indicate how each of the items listed would be handled in...
Using the code letters below, indicate how each of the items listed would be handled in preparing a bank reconciliation for the month of May for Pinar dairy Company. (8 points) Code A Add to cash balance per Banks B Deduct from cash balance per Banks C Add to cash balance per Book D Deduct from cash balance per Book E Does not affect the bank reconciliation Deposits of May 30 and 31 not yet recorded by bank $9,000 and...
Using the code letters below, indicate how each of the items listed would be handled in...
Using the code letters below, indicate how each of the items listed would be handled in preparing a bank reconciliation for the month of March for Unipal company. (8 points) Code A Add to cash balance per Banks B Deduct from cash balance per Banks C Add to cash balance per Book D Deduct from cash balance per Book E Does not affect the bank reconciliation A check for $127 written to the company by J. Chandler was returned NSF...
Using the code letters below, indicate how each of the items listed would be handled in...
Using the code letters below, indicate how each of the items listed would be handled in preparing a bank reconciliation for the month of March for Unipal company. (8 points)    Code A Add to cash balance per Banks B Deduct from cash balance per Banks C Add to cash balance per Book D Deduct from cash balance per Book E Does not affect the bank reconciliation A check for $127 written to the company by J. Chandler was returned...
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the...
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the users enters a negative number. The program then prints out: a) the sum of all the numbers b) the average of all the numbers c) the max of the numbers d) the min of the numbers Note we did not cover lists (array) so you will not use them in this problem. Finally, ask the user for their name, then print their name as...
#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT