Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Minimal Level

For the minimal level, you only need to create a single file. The output file is same_order.txt. The sentences in the output file shall be in the order that the data appears in the data file, presidents.txt. (Can you figure out what that order is? Participation points)

Here is some pseudo-code for creating same_order.txt:

open the input file open the output file for each line in the input file: call your function to write out the sentence close the input file close the output file

This pseudo-code will work for either version of the helper function. You just have to keep in mind how much work is going on in your helper function. (Actually, if you're only doing the minimal version, there is no advantage to creating the helper function.)

help with python it's a simple code

Sample output

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

Abraham Lincoln was president from 3/4/1861 to 4/15/1865. Andrew Jackson was president from 3/4/1829 to 3/4/1837. Andrew Johnson was president from 4/15/1865 to 3/4/1869.

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

Step: 3

blur-text-image

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

Different types of Grading?

Answered: 1 week ago

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago