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

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 \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.

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:

Buchanan(tab)James(tab)3/4/1857(tab)3/4/1861( ) 

input file:

Lincoln Abraham 3/4/1861 4/15/1865 Jackson Andrew 3/4/1829 3/4/1837 Johnson Andrew 4/15/1865 3/4/1869 Obama Barack 1/20/2009 incumbant Harrison Benjamin 3/4/1889 3/4/1893 Clinton Bill 1/20/1993 1/20/2001 Coolidge Calvin 8/2/1923 3/4/1929 Arthur Chester A 9/19/1881 3/4/1885 Eisenhower Dwight D 1/20/1953 1/20/1961 Pierce Franklin 3/4/1853 3/4/1857 Roosevelt Franklin D 3/4/1933 4/12/1945 Washington George 4/30/1789 3/4/1797 Bush George H W 1/20/1989 1/20/1993 Bush George W 1/20/2001 1/20/2009 Ford Gerald 8/9/1974 1/20/1977 Cleveland Grover 3/4/1885 3/4/1889 Cleveland Grover 3/4/1893 3/4/1897 Truman Harry S 4/12/1945 1/20/1953 Hoover Herbert 3/4/1929 3/4/1933 Madison James 3/4/1809 3/4/1817 Monroe James 3/4/1817 3/4/1825 Buchanan James 3/4/1857 3/4/1861 Garfield James A 3/4/1881 9/19/1881 Polk James K 3/4/1845 3/4/1849 Carter Jimmy 1/20/1977 1/20/1981 Adams John 3/4/1797 3/4/1801 Tyler John 4/4/1841 3/4/1845 Kennedy John F 1/20/1961 11/22/1963 Adams John Quincy 3/4/1825 3/4/1829 Johnson Lyndon B 11/22/1963 1/20/1969 Van Buren Martin 3/4/1837 3/4/1841 Fillmore Millard 7/9/1850 3/4/1853 Nixon Richard M 1/20/1969 8/9/1974 Reagan Ronald 1/20/1981 1/20/1989 Hayes Rutherford B 3/4/1877 3/4/1881 Roosevelt Theodore 9/14/1901 3/4/1909 Jefferson Thomas 3/4/1801 3/4/1809 Grant Ulysses S 3/4/1869 3/4/1877 Harding Warren G 3/4/1921 8/2/1923 McKinley William 3/4/1897 9/14/1901 Harrison William Henry 3/4/1841 4/4/1841 Taft William Howard 3/4/1909 3/4/1913 Wilson Woodrow 3/4/1913 3/4/1921 Taylor Zachary 3/4/1849 7/9/1850 

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!