The president of the United States is not chosen directly. Actually, on the day of the elections, it is not the president that gets chosen, but the college that is going to choose the president. The electoral college consists of 538 electors. That is the same number as the amount of senators and representatives, completed with three extra seats for Washington D.C. Because the number of delegates differs in each state, there is a difference in number of electors per state. The minimum number of electors per state is three, since every state has two senators and at least one representative.
Most state laws establish a winner-take-all system, wherein the ticket that wins a plurality of votes wins all of that state's allocated electoral votes, and thus has their slate of electors chosen to vote in the Electoral College. Maine and Nebraska do not use this method, opting instead to give two electoral votes to the statewide winner and one electoral vote to the winner of each Congressional district. For this assignment however, we will ignore this exception and we presume that the first past the post principle applies to all states.
The two largest parties in the United States are the Democratic Party and the Republican Party. Furthermore, there are some smaller parties (the Liberal Party, the Green Party and the Constitutional Party, amongst others), but we will not take this into account for this assignment.
After every census, that is taken in the U.S. every ten years, the number of delegates and electors per state is adapted. We use the following order for the states: California, Texas, Florida, New York, Illinois, Pennsylvania, Ohio, Georgia, Michigan, North Carolina, New Jersey, Virginia, Washington, Arizona, Indiana, Massachusetts, Tennessee, Maryland, Minnesota, Missouri, Wisconsin, Alabama, Colorado, South Carolina, Kentucky, Louisiana, Connecticut, Oklahoma, Oregon, Arkansas, Iowa, Kansas, Mississippi, Nevada, Utah, Nebraska, New Mexico, West Virginia, Hawaï, Idaho, Maine, New Hampshire, Rhode Island, Alaska, Delaware, District of Columbia, Montana, North Dakota, South Dakota, Vermont and Wyoming. In the same order, the number of electors per state from 2010 until 2020 is: 55, 38, 29, 29, 20, 20, 18, 16, 16, 15, 14, 13, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 7, 6, 6, 6, 6, 6, 6, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3 and 3.
Write a function electors to which a list of tuples should be given. Every tuple contains two whole numbers, that represent the number of votes for the Democratic Party — resp. the Republican Party — in a certain state. The function should print a list of tuples, where a tuple indicates whether the electors are for the Democratic Party (first element is True) or for the Republican Party (first element is False), and the total amount of electors in that state (second element of the tuple). All this is determined based on the distribution of electors for the period 2010-2020. However, another argument called distribution can be given to the function. If this is the case, this argument is used to determine the distribution of the electors.
Use the function electors in order to write a function result. This function takes the same argument as the function above, but it returns only one tuple. This tuple contains in the first position the number of electors for the Democratic Party and in the second position the number of electors of the Republican Party.
>>> votes2008 = [
... (8274473, 5011781), (3528633, 4479328), (4282074, 4045624),
... (4804701, 2752728), (3419348, 2031179), (3276363, 2655885),
... (2940044, 2677820), (1844123, 2048759), (2872579, 2048639),
... (2142651, 2128474), (2215422, 1613207), (1959532, 1725005),
... (1750848, 1229216), (1034707, 1230111), (1374039, 1345648),
... (1904097, 1108854), (1087437, 1479178), (1629467, 959862),
... (1573354, 1275409), (1441911, 1445814), (1677211, 1262393),
... (813479, 1266546), (1288576, 1073589), (862449, 1034896),
... (751985, 1048462), (782989, 1148275), (997772, 629428),
... (502496, 960165), (1037291, 738475), (422310, 638017),
... (828940, 682379), (514765, 699655), (554662, 724597), (533736, 412827),
... (327670, 596030), (333319, 452979), (472422, 346832), (303857, 397466),
... (325871, 120566), (236440, 403012), (421923, 295273), (384826, 316534),
... (296571, 165391), (123594, 193841), (255459, 152374), (245800, 17367),
... (231667, 242763), (141278, 168601), (170924, 203054), (219262, 98974),
... (82868, 164958)
... ]
>>> electors(votes2008)
... [
... (True, 55), (False, 38), (True, 29), (True, 29), (True, 20), (True, 20),
... (True, 18), (False, 16), (True, 16), (True, 15), (True, 14), (True, 13),
... (True, 12), (False, 11), (True, 11), (True, 11), (False, 11), (True, 10),
... (True, 10), (False, 10), (True, 10), (False, 9), (True, 9), (False, 9),
... (False, 8), (False, 8), (True, 7), (False, 7), (True, 7), (False, 6),
... (True, 6), (False, 6), (False, 6), (True, 6), (False, 6), (False, 5),
... (True, 5), (False, 5), (True, 4), (False, 4), (True, 4), (True, 4),
... (True, 4), (False, 3), (True, 3), (True, 3), (False, 3), (False, 3),
... (False, 3), (True, 3), (False, 3)
... ]
>>> result(votes2008)
(358, 180)
>>> distribution2000 = [
... 55, 34, 27, 31, 21, 21, 20, 15, 17, 15, 15, 13, 11, 10, 11, 12, 11, 10,
... 10, 11, 10, 9, 9, 8, 8, 9, 7, 7, 7, 6, 7, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4,
... 4, 4, 3, 3, 3, 3, 3, 3, 3, 3
... ]
>>> result(votes2008, distribution2000)
(364, 174)