# Presidents.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-21 File created. # 2022-12-27 Converted to Python 3. # When this program is executed, Date.py must be in the same # folder (directory) together with this file. from Date import Date class President : def __init__( self, given_president_name, birth_date_as_string, given_birth_state, given_party_name, inauguration_date_as_string, last_day_in_office_as_string, given_vice_president_name ) : self.president_name = given_president_name self.birth_date_of_president = Date( birth_date_as_string ) self.birth_state_of_president = given_birth_state self.party_name = given_party_name self.inauguration_date = Date( inauguration_date_as_string ) self.last_day_in_office = Date( last_day_in_office_as_string ) self.vice_president_name = given_vice_president_name def get_president_name( self ) : return self.president_name def was_president_on( self, given_date ) : return given_date.is_within_dates( self.inauguration_date, self.last_day_in_office ) def get_brief_president_info( self ) : return "\n %-25s president from %s to %s" % ( self.president_name, self.inauguration_date, self.last_day_in_office ) def get_full_president_data( self ) : time_in_office = \ self.inauguration_date.get_distance_to( self.last_day_in_office ) return "\n %s born %s, %s" \ "\n Inauguration date : %s" \ "\n Last day in office : %s" \ "\n Total time in office: %d years, %d months, and %d days."\ "\n Party: %s" \ "\n Vice president(s): %s" % ( self.president_name, self.birth_date_of_president, self.birth_state_of_president, self.inauguration_date, self.last_day_in_office, time_in_office.years, time_in_office.months, time_in_office.days, self.party_name, self.vice_president_name ) class PresidentInfoApplication : def __init__( self ) : self.SEARCH_NOT_READY = 1 self.SEARCH_IS_READY = 2 self.SEARCH_IS_SUCCESSFUL = 3 self.SEARCH_NOT_SUCCESSFUL = 4 self.president_table = [] self.index_of_last_printing = 0 self.president_table.append( President( "George Washington", "02/22/1732", "Virginia", "Federalist", "04/30/1789", "03/03/1797", "John Adams") ) self.president_table.append( President("John Adams", "10/30/1735", "Massachusetts", "Federalist", "03/04/1797", "03/03/1801", "Thomas Jefferson") ) self.president_table.append( President("Thomas Jefferson", "04/13/1743", "Virginia", "Dem.-Rep.", "03/04/1801", "03/03/1809", "Aaron Burr + George Clinton") ) self.president_table.append( President("James Madison", "03/16/1751", "Virginia", "Dem.-Rep.", "03/04/1809", "03/03/1817", "George Clinton + Elbridge Gerry" ) ) self.president_table.append( President( "James Monroe", "04/28/1758", "Virginia", "Dem.-Rep.", "03/04/1817", "03/03/1825", "Daniel D. Tompkins" ) ) self.president_table.append( President( "John Quincy Adams", "07/11/1767", "Massachusetts", "Dem.-Rep.", "03/04/1825", "03/03/1829", "John C. Calhoun" ) ) self.president_table.append( President( "Andrew Jackson", "03/15/1767", "South Carolina","Democrat", "03/04/1829", "03/03/1837", "John C. Calhoun + Martin Van Buren" ) ) self.president_table.append( President( "Martin Van Buren", "12/05/1782", "New York", "Democrat", "03/04/1837", "03/03/1841", "Richard M. Johnson" ) ) self.president_table.append( President( "William Henry Harrison", "02/09/1773", "Virginia", "Whig", "03/04/1841", "04/04/1841", "John Tyler" ) ) self.president_table.append( President( "John Tyler", "03/29/1790", "Virginia", "Whig", "04/06/1841", "03/03/1845", "" ) ) self.president_table.append( President( "James Knox Polk", "11/02/1795", "North Carolina", "Democrat", "03/04/1845", "03/03/1849", "George M. Dallas" ) ) self.president_table.append( President( "Zachary Taylor", "11/24/1784", "Virginia", "Whig", "03/05/1849", "07/09/1850", "Millard Fillmore" ) ) self.president_table.append( President( "Millard Fillmore", "01/07/1800", "New York", "Whig", "07/10/1850", "03/03/1853", "" ) ) self.president_table.append( President( "Franklin Pierce", "11/23/1804", "New Hampshire", "Democrat", "03/04/1853", "03/03/1857", "William R. King" ) ) self.president_table.append( President( "James Buchanan", "04/23/1791", "Pennsylvania", "Democrat", "03/04/1857", "03/03/1861", "John C. Breckinridge") ) self.president_table.append( President( "Abraham Lincoln", "02/12/1809", "Kentucky", "Republican", "03/04/1861", "04/15/1865", "Hannibal Hamlin + Andrew Johnson" ) ) self.president_table.append( President( "Andrew Johnson", "12/29/1808", "North Carolina", "Democrat", "04/15/1865", "03/03/1869", "" ) ) self.president_table.append( President( "Ulysses Simpson Grant", "04/27/1822", "Ohio", "Republican", "03/04/1869", "03/03/1877", "Schuyler Colfax + Henry Wilson" ) ) self.president_table.append( President( "Rutherford Birchard Hayes", "10/04/1822", "Ohio", "Republican", "03/04/1877", "03/03/1881", "William A. Wheeler") ) self.president_table.append( President( "James Abram Garfield", "11/19/1831", "Ohio", "Republican", "03/04/1881", "09/19/1881", "Chester Alan Arthur") ) self.president_table.append( President( "Chester Alan Arthur", "10/05/1829", "Vermont", "Republican", "09/20/1881", "03/03/1885", "" ) ) self.president_table.append( President( "Grover Cleveland", "03/18/1837", "New Jersey", "Democrat", "03/04/1885", "03/03/1889", "Thomas A. Hendrics" ) ) self.president_table.append( President( "Benjamin Harrison", "08/20/1933", "Ohio", "Republican", "03/04/1889", "03/03/1893", "Levi P. Morton" ) ) self.president_table.append( President( "Grover Cleveland", "03/18/1837", "New Jersey", "Democrat", "03/04/1893", "03/03/1897", "Adlai E. Stevenson" ) ) self.president_table.append( President( "William McKinley", "01/29/1843", "Ohio", "Republican", "03/04/1897", "09/14/1901", "Garret A. Hobart + Theodore Roosevelt" ) ) self.president_table.append( President( "Theodore Roosevelt", "10/27/1858", "New York", "Republican", "09/14/1901","03/03/1909","Charles W. Fairbanks") ) self.president_table.append( President( "William Howard Taft", "09/15/1857", "Ohio", "Republican", "03/04/1909", "03/03/1913", "James S. Sherman") ) self.president_table.append( President( "Woodrow Wilson", "12/28/1856", "Virginia", "Democrat", "03/04/1913", "03/03/1921", "Thomas R. Marshall" ) ) self.president_table.append( President( "Warren Gamaliel Harding", "11/02/1865", "Ohio", "Republican", "03/04/1921", "08/02/1923", "Calvin Coolidge" ) ) self.president_table.append( President( "Calvin Coolidge", "07/04/1872", "Vermont", "Republican", "08/03/1923", "03/03/1929", "Charles G. Dawes" ) ) self.president_table.append( President( "Herbert Clark Hoover", "08/10/1874", "Iowa", "Republican", "03/04/1929", "03/03/1933", "Charles Curtis" ) ) self.president_table.append( President( "Franklin Delano Roosevelt","01/30/1882","New York", "Democrat", "03/04/1933", "04/12/1945", "John N. Garner + Henry A. Wallace + Harry S. Truman" ) ) self.president_table.append( President( "Harry S. Truman", "05/08/1884", "Missouri", "Democrat", "04/12/1945", "01/20/1953", "Alben W. Barkley" ) ) self.president_table.append( President( "Dwight David Eisenhover", "10/14/1890", "Texas", "Republican","01/20/1953","01/20/1961","Richard Milhous Nixon") ) self.president_table.append( President( "John Fitzgerald Kennedy", "05/29/1917", "Massachusetts", "Democrat", "01/20/1961", "11/22/1963", "Lyndon Baines Johnson" ) ) self.president_table.append( President( "Lyndon Baines Johnson", "08/27/1908", "Texas", "Democrat", "11/22/1963", "01/20/1969", "Hubert H. Humphrey") ) self.president_table.append( President( "Richard Milhous Nixon", "01/09/1913", "California", "Republican", "01/20/1969", "08/09/1974", "Spiro T. Agnew + Gerald Rudolph Ford") ) self.president_table.append( President( "Gerald Rudolph Ford", "07/14/1913", "Nebraska", "Republican","08/09/1974","01/20/1977","Nelson A. Rockefeller") ) self.president_table.append( President( "Jimmy (James Earl) ) Carter", "10/01/1924", "Georgia", "Democrat", "01/20/1977", "01/20/1981", "Walter F. Mondale" ) ) self.president_table.append( President( "Ronald Wilson Reagan", "02/06/1911", "Illinois", "Republican", "01/20/1981", "01/20/1989", "George Bush" ) ) self.president_table.append( President( "George Bush", "06/12/1924", "Massachusetts", "Republican", "01/20/1989", "01/20/1993", "Dan Quayle" ) ) self.president_table.append( President( "Bill Clinton", "08/19/1946", "Arkansas", "Democrat", "01/20/1993", "01/20/2001", "Albert Gore" ) ) self.president_table.append( President( "George W. Bush", "07/06/1946", "Connecticut", "Republican", "01/20/2001", "01/20/2009", "Richard Cheney" ) ) def search_president_by_name( self ) : print( "\n Enter first, last, or full name of president: ", end="" ) given_president_name = input() president_index = 0 array_search_status = self.SEARCH_NOT_READY while array_search_status == self.SEARCH_NOT_READY : if self.president_table[ president_index ].get_president_name() \ .find( given_president_name ) != -1 : array_search_status = self.SEARCH_IS_SUCCESSFUL elif president_index >= len( self.president_table ) - 1 : array_search_status = self.SEARCH_NOT_SUCCESSFUL else : president_index += 1 if array_search_status == self.SEARCH_IS_SUCCESSFUL : print( "\n\n THE #%d PRESIDENT OF THE UNITED STATES: " % \ ( president_index + 1 ) ) print( self.president_table[ president_index ]. \ get_full_president_data() ) self.index_of_last_printing = president_index else : print( "\n\n Sorry, could not find \"%s\" in table." % \ given_president_name ) def search_president_for_given_date( self ) : print( "\n Please, type in a date in form MM/DD/YYYY " \ "\n Use two digits for days and months, and " \ "\n four digits for year: ", end="" ) date_as_string = input() date_of_interest = Date( date_as_string ) president_index = 0 array_search_status = self.SEARCH_NOT_READY while array_search_status == self.SEARCH_NOT_READY : if self.president_table[ president_index ]. \ was_president_on( date_of_interest ) : array_search_status = self.SEARCH_IS_SUCCESSFUL elif president_index >= len( self.president_table ) - 1 : array_search_status = self.SEARCH_NOT_SUCCESSFUL else : president_index += 1 if array_search_status == self.SEARCH_IS_SUCCESSFUL : print( "\n\n ON %s, THE PRESIDENT OF THE UNITED STATES WAS:" % \ date_of_interest ) print( self.president_table[ president_index ]. \ get_full_president_data() ) self.index_of_last_printing = president_index else : print( "\n\n Sorry, no president was on duty on %s." % \ date_of_interest ) def print_data_of_next_president( self ) : if self.index_of_last_printing < len( self.president_table ) - 1 : self.index_of_last_printing += 1 print( "\n\n THE #%d PRESIDENT OF THE UNITED STATES: " % \ ( self.index_of_last_printing + 1 ) ) print( self.president_table[ self.index_of_last_printing ]. \ get_full_president_data() ) else : print( "\n Sorry, no more presidents in table.", end="" ) def print_list_of_all_presidents( self ) : president_index = 0 while president_index < len( self.president_table ) : print( self.president_table[ president_index ]. \ get_brief_president_info(), end="" ) president_index += 1 if president_index % 15 == 0 : print( "\nPress to continue .....", end="" ) any_string_from_keyboard = input() def run( self ) : user_selection = "????" print( "\n This program provides information about all" \ "\n presidents of the U.S.A. Please, select from" \ "\n the following menu by typing in a letter. ", end="" ) while user_selection[ 0 ] != 'e' : print( "\n\n p Search president by name." \ "\n d Search president for a given date." \ "\n n Print data of next president." \ "\n a Print list of all presidents." \ "\n e Exit the program.\n\n ", end="" ) user_selection = input() if user_selection[ 0 ] == 'p' : self.search_president_by_name() elif user_selection[ 0 ] == 'd' : self.search_president_for_given_date() elif user_selection[ 0 ] == 'n' : self.print_data_of_next_president() elif user_selection[ 0 ] == 'a' : self.print_list_of_all_presidents() # The main program. this_president_info_application = PresidentInfoApplication() this_president_info_application.run()