Last active
January 17, 2016 21:57
-
-
Save vampjaz/3a3dfc7ebb43245c2db1 to your computer and use it in GitHub Desktop.
Short study program for presidents and their political parties.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### presidents study program | |
import os,sys,random | |
## data from https://raw.githubusercontent.com/m0rt1m3r/US-Presidents/master/USPresidents.csv | |
## ['No ', 'President Name ', 'Took office ', 'Left office ', 'Party '] | |
data = [['1', 'George Washington', '30/04/1789', '4/03/1797', 'Independent'], ['2', 'John Adams', '4/03/1797', '4/03/1801', 'Federalist'], ['3', 'Thomas Jefferson', '4/03/1801', '4/03/1809', 'Democratic-Republican'], ['4', 'James Madison', '4/03/1809', '4/03/1817', 'Democratic-Republican'], ['5', 'James Monroe', '4/03/1817', '4/03/1825', 'Democratic-Republican'], ['6', 'John Quincy Adams', '4/03/1825', '4/03/1829', 'Democratic-Republican'], ['7', 'Andrew Jackson', '4/03/1829', '4/03/1837', 'Democratic'], ['8', 'Martin Van Buren', '4/03/1837', '4/03/1841', 'Democratic'], ['9', 'William Henry Harrison', '4/03/1841', '4/04/1841', 'Whig'], ['10', 'John Tyler', '4/04/1841', '4/03/1845', 'Whig'], ['11', 'James K. Polk', '4/03/1845', '4/03/1849', 'Democratic'], ['12', 'Zachary Taylor', '4/03/1849', '9/07/1850', 'Whig'], ['13', 'Millard Fillmore', '9/07/1850', '4/03/1853', 'Whig'], ['14', 'Franklin Pierce', '4/03/1853', '4/03/1857', 'Democratic'], ['15', 'James Buchanan', '4/03/1857', '4/03/1861', 'Democratic'], ['16', 'Abraham Lincoln', '4/03/1861', '15/04/1865', 'Republican'], ['17', 'Andrew Johnson', '15/04/1865', '4/03/1869', 'Democratic'], ['18', 'Ulysses S. Grant', '4/03/1869', '4/03/1877', 'Republican'], ['19', 'Rutherford B. Hayes', '4/03/1877', '4/03/1881', 'Republican'], ['20', 'James A. Garfield', '4/03/1881', '19/09/1881', 'Republican'], ['21', 'Chester A. Arthur', '19/09/1881', '4/03/1885', 'Republican'], ['22', 'Grover Cleveland', '4/03/1885', '4/03/1889', 'Democratic'], ['23', 'Benjamin Harrison', '4/03/1889', '4/03/1893', 'Republican'], ['24', 'Grover Cleveland (2nd term)', '4/03/1893', '4/03/1897', 'Democratic'], ['25', 'William McKinley', '4/03/1897', '14/09/1901', 'Republican'], ['26', 'Theodore Roosevelt', '14/09/1901', '04/03/1909', 'Republican'], ['27', 'William Howard Taft', '04/03/1909', '04/03/1913', 'Republican'], ['28', 'Woodrow Wilson', '04/03/1913', '04/03/1921', 'Democratic'], ['29', 'Warren G. Harding', '04/03/1921', '02/08/1923', 'Republican'], ['30', 'Calvin Coolidge', '02/08/1923', '04/03/1929', 'Republican'], ['31', 'Herbert Hoover', '04/03/1929', '04/03/1933', 'Republican'], ['32', 'Franklin D. Roosevelt', '04/03/1933', '12/04/1945', 'Democratic'], ['33', 'Harry S. Truman', '12/04/1945', '20/01/1953', 'Democratic'], ['34', 'Dwight D. Eisenhower', '20/01/1953', '20/01/1961', 'Republican'], ['35', 'John F. Kennedy', '20/01/1961', '22/11/1963', 'Democratic'], ['36', 'Lyndon B. Johnson', '22/11/1963', '20/01/1969', 'Democratic'], ['37', 'Richard Nixon', '20/01/1969', '09/08/1974', 'Republican'], ['38', 'Gerald Ford', '09/08/1974', '20/01/1977', 'Republican'], ['39', 'Jimmy Carter', '20/01/1977', '20/01/1981', 'Democratic'], ['40', 'Ronald Reagan', '20/01/1981', '20/01/1989', 'Republican'], ['41', 'George H. W. Bush', '20/01/1989', '20/01/1993', 'Republican'], ['42', 'Bill Clinton', '20/01/1993', '20/01/2001', 'Democratic'], ['43', 'George W. Bush', '20/01/2001', '20/01/2009', 'Republican'], ['44', 'Barack Obama', '20/01/2009', 'Incumbent', 'Democratic']] | |
names = [i[1].strip() for i in data] | |
parties = list(set([i[4].strip() for i in data])) | |
try: | |
mode = sys.argv[1] | |
except: | |
print "Usage: {} <list/test>".format(sys.argv[0]) | |
sys.exit(1) | |
if mode == 'list': | |
for i in data: | |
print '\t'.join(i) | |
elif mode == 'test': | |
for i in data: | |
random.shuffle(names) | |
random.shuffle(parties) | |
print "President {}:".format(i[0]) | |
namec = list(set([i[1]] + names[:4]))[:4] | |
random.shuffle(namec) | |
print " Name?" | |
for l,j in zip('ABCD',namec): | |
print "\t{}: {}".format(l,j) | |
while 1: | |
try: | |
ans = raw_input(" >> ").strip().lower()[0] | |
if i[1] == namec[{'a':0,'b':1,'c':2,'d':3}.get(ans,1000000)]: | |
print "Correct!!" | |
break | |
else: | |
print "incorrect" | |
except KeyboardInterrupt: | |
sys.exit(0) | |
except: | |
print "invalid input" | |
partc = list(set([i[4]] + parties[:4]))[:4] | |
random.shuffle(partc) | |
print " {}'s Party?".format(i[1]) | |
for l,j in zip('ABCD',partc): | |
print "\t{}: {}".format(l,j) | |
while 1: | |
try: | |
ans = raw_input(" >> ").strip().lower()[0] | |
if i[4] == partc[{'a':0,'b':1,'c':2,'d':3}.get(ans,1000000)]: | |
print "Correct!!", | |
break | |
else: | |
print "incorrect" | |
except KeyboardInterrupt: | |
sys.exit(0) | |
except: | |
print "invalid input" | |
print "{} was {}".format(i[1],i[4]) | |
print '-'*30 | |
else: | |
print "Usage: {} <list/test>".format(sys.argv[0]) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment