Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help with python Download the data file for this assignment, presidents.txt. (Please note: This file uses the lf (line feed) as the line terminator. Classic

help with python

Download the data file for this assignment, presidents.txt. (Please note: This file uses the lf (line feed) as the line terminator. Classic MS-DOS and Windows used cr-lf (carriage return - line feed) as the line terminator. Modern Windows tools will display this file correctly. Older Windows tools, like Notepad, will not. The file you download is correct. To verify this, open the file using the IDLE editor.)

Each line in this file has four pieces of information, separated by tabs.

Last name \t First name \t Date took office \t Date left office

The basic task for this lab is to read through the data file, and create an output file which will contain sentences with the information read from the data file. For example, the first line of the file is:

Lincoln\tAbraham\t3/4/1861\t4/15/1865

The four pieces of information are:

  • Lincoln
  • Abraham
  • 3/4/1861
  • 4/15/1865

The output sentence for this data is:

Abraham Lincoln was president from 3/4/1861 to 4/15/1865.

It should be pretty obvious how the four pieces of data are put together into the output sentence. If you have questions, ask in the forum. Please note: There is a period at the end of the sentence. There will be a functionality deduction if the period is not present or misplaced in the output files.

Output File(s)

To get practice writing files, the all of the output from this assignment will be written to files. That is, this program should not print anything to the console. You may use console output (calls to the print function) for debugging while you are developing the program. However, these should be removed or commented out before you submit the program for grading.

Each level of the assignment (minimal, standard, and challenge) has its own output order. So, each different order will be written to a separate file.

You can take advantage of this fact by creating a function that will take the input text and generate the output sentence. There are two options that come to mind:

  • A function that takes two parameters: the input data, and the file object. The function can generate the sentence and immediately write it to the file object. Notice, this suggests that the second parameter is the file object, rather than the filename. So, after you open the output file for writing, you get the file object. Pass this to the function. That way the output file only needs to be opened once.
  • A function that takes a single string parameter, that is, the input data, and returns the sentence generated using that data. The caller will have to take that return value and write it to the output file.

Standard Level

For the standard level, you need to create two files. The two output files are: same_order.txt and last_name.txt. The first, same_order.txt, is the same as the one created for the minimal version, with the sentences in the same order as the data in the presidents.txt file. In the second file, last_name.txt, the sentences shall be ordered by last name. In those cases where the last names are the same, the Johnsons, the Adamses, and the Bushes, sort by first name. If you're really concerned, the two discontiguous terms by Grover Cleveland can be ordered by date.

To accomplish this, read the whole file into the program, and rearrange the data within your program. (Hint: see section 7.5 of the text.)

Sample output

Here is what the beginning of the output file last_name.txt should look like:

John Adams was president from 3/4/1797 to 3/4/1801. John Quincy Adams was president from 3/4/1825 to 3/4/1829. Chester A Arthur was president from 9/19/1881 to 3/4/1885.

Challenge Level

For the challenge level, you need to create three files. The first two are those described for the standard version. The additional file is inauguration.txt. The sentence shall be in the order set by date that the president took office. This will give the "familiar" ordering: Washington, Adams, Jefferson, Madison, Monroe, etc.

Please note, both William Henry Harrison and James A Garfield served less than one year as president. So, you should include the month that the president took office as you order the data, not just the year. As with the standard version, the data should be ordered within your code, rather than trying to rearrange the input data file.

Sample output

Here is what the beginning of the output file inauguration.txt should look like:

George Washington was president from 4/30/1789 to 3/4/1797. John Adams was president from 3/4/1797 to 3/4/1801. Thomas Jefferson was president from 3/4/1801 to 3/4/1809.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What lessons in OD contracting does this case represent?

Answered: 1 week ago

Question

Does the code suggest how long data is kept and who has access?

Answered: 1 week ago