Python 3 presidents list Using python 3 I need help writing a program that will
ID: 3845557 • Letter: P
Question
Python 3 presidents list
Using python 3 I need help writing a program that will read presidents.txt
Each line in this file has four pieces of information, separated by tabs.
Last name First name Date took office 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 Abraham 3/4/1861 4/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.
Input file:
keep in mind this may display inappropriatelyas it may not format properly on this site and in actuality the code in the .txt is similar to the below example:
input file:
The first output file needs to be named same_order.txt, thus far my pseudo code is:
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
with an output of:
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.
the second output file needs to be named last_name.txt and have an output like this:
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.
In the cases where the last names are the same, the Johnsons, the Adams's, and the Bushes, sort by first name
The third and final output file needs to be named inauguration.txt with an output that looks like this:
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.
for both William Henry Harrison and James A Garfield who served less than one year as president. I should include the month that the president took office as the order of data, not just the year.
And mainly trying to keep the data ordered within code, rather than trying to rearrange the input data file
Explanation / Answer
2.data.txt will have the above lines which needs to be parsed.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.