Question: In Python Only!! Make sure to use the dictionary below Please !! The Electoral College plays a pivotal role in the election of the President

In Python Only!!

Make sure to use the dictionary below Please !!

The Electoral College plays a pivotal role in the election of the President of the US. In order to be elected Prescient of the Noted States a candidate must gain 270 of the possible 538 Electoral College votes. The following is a dictionary of the states, the number of electoral votes for each state and the winner of the state. The key is the name of state, the value is a list containing the number of votes for that stare and the projected winner ('U' for Unknown). Assume that Winston, Charlotte and Penny are all running for President I this assignment you are to write a program that will randomly assign a state to one of the candidates, you must do so for all of the states. Doing so may not gather enough votes for one candidate to win. You must therefore repeat the process of assigning the states to candidates until one candidate wins (remember 270 of the possible 538 votes are needed to win).

Your program must: output the states won by each candidate (sorted alphabetically),

the total electoral votes for each candidate

the winner of the election

the number of repetitions needed to have a candidate win enough votes for election.

Here is a dictionary of the states and their respective electoral votes, please copy and past this code to your file ec = {'Alabama': [9,'U'], 'Kentucky' : [8,'U'], 'North Dakota' : [3,'U'], 'Alaska' : [3,'U'], 'Louisiana' : [8,'U'], 'Ohio' : [18,'U'], 'Arizona' : [11,'U'], 'Maine' : [4,'U'], 'Oklahoma' : [7,'U'], 'Arkansas' : [6,'U'], 'Maryland' : [10,'U'], 'Oregon' : [7,'U'], 'California' : [55,'U'], 'Massachusetts' : [11,'U'], 'Pennsylvania' : [20,'U'], 'Colorado': [9,'U'], 'Michigan' : [16,'U'], 'Rhode Island' : [4,'U'], 'Connecticut' : [7,'U'], 'Minnesota' : [10,'U'], 'South Carolina' : [9,'U'], 'Delaware' : [3,'U'], 'Mississippi' : [6,'U'], 'South Dakota' : [3,'U'], 'District of Columbia' : [3,'U'], 'Missouri' : [10,'U'], 'Tennessee' : [11,'U'], 'Florida' : [29,'U'], 'Montana' : [3,'U'], 'Texas' : [38,'U'], 'Georgia' : [16,'U'], 'Nebraska' : [5,'U'], 'Utah' : [6,'U'], 'Hawaii' : [4,'U'], 'Nevada' : [6,'U'], 'Vermont' : [3,'U'], 'Idaho' : [4,'U'], 'New Hampshire' : [4,'U'], 'Virginia' : [13,'U'], 'Illinois' : [20,'U'], 'New Jersey' : [14,'U'], 'Washington' : [12,'U'], 'Indiana' : [11,'U'], 'New Mexico' : [5,'U'], 'West Virginia' : [5,'U'], 'Iowa' : [6,'U'], 'New York' : [29,'U'], 'Wisconsin' : [10,'U'], 'Kansas' : [6,'U'], 'North Carolina' : [15,'U'], 'Wyoming' : [3,'U'], }

The output should look like this but it varies because it's random

The following are the results votes of the electoral college by state. {'Alabama': [9, 'Winston'], 'Kentucky': [8, 'Winston'], 'North Dakota': [3, 'Charlotte'], 'Alaska': [3, 'Charlotte'], 'Louisiana': [8, 'Charlotte'], 'Ohio': [18, 'Penny'], 'Arizona': [11, 'Winston'], 'Maine': [4, 'Penny'], 'Oklahoma': [7, 'Penny'], 'Arkansas': [6, 'Penny'], 'Maryland': [10, 'Charlotte'], 'Oregon': [7, 'Winston'], 'California': [55, 'Penny'], 'Massachusetts': [11, 'Penny'], 'Pennsylvania': [20, 'Penny'], 'Colorado': [9, 'Penny'], 'Michigan': [16, 'Penny'], 'Rhode Island': [4, 'Winston'], 'Connecticut': [7, 'Penny'], 'Minnesota': [10, 'Penny'], 'South Carolina': [9, 'Winston'], 'Delaware': [3, 'Penny'], 'Mississippi': [6, 'Penny'], 'South Dakota': [3, 'Penny'], 'District of Columbia': [3, 'Charlotte'], 'Missouri': [10, 'Winston'], 'Tennessee': [11, 'Winston'], 'Florida': [29, 'Charlotte'], 'Montana': [3, 'Winston'], 'Texas': [38, 'Penny'], 'Georgia': [16, 'Penny'], 'Nebraska': [5, 'Charlotte'], 'Utah': [6, 'Charlotte'], 'Hawaii': [4, 'Penny'], 'Nevada': [6, 'Winston'], 'Vermont': [3, 'Charlotte'], 'Idaho': [4, 'Winston'], 'New Hampshire': [4, 'Charlotte'], 'Virginia': [13, 'Penny'], 'Illinois': [20, 'Penny'], 'New Jersey': [14, 'Charlotte'], 'Washington': [12, 'Charlotte'], 'Indiana': [11, 'Penny'], 'New Mexico': [5, 'Penny'], 'West Virginia': [5, 'Winston'], 'Iowa': [6, 'Charlotte'], 'New York': [29, 'Penny'], 'Wisconsin': [10, 'Charlotte'], 'Kansas': [6, 'Winston'], 'North Carolina': [15, 'Penny'], 'Wyoming': [3, 'Charlotte']}

This is how the output should look like: The number of elections held: 6

The final tally of votes: Winston: 93 Charlotte: 119 Penny: 326}

The winner of the election is Penny

States won by Winston : ['Alabama', 'Arizona', 'Idaho', 'Kansas', 'Kentucky', 'Missouri', 'Montana', 'Nevada', 'Oregon', 'Rhode Island', 'South Carolina', 'Tennessee', 'West Virginia']

States won by Charlotte : ['Alaska', 'District of Columbia', 'Florida', 'Iowa', 'Louisiana', 'Maryland', 'Nebraska', 'New Hampshire', 'New Jersey', 'North Dakota', 'Utah', 'Vermont', 'Washington', 'Wisconsin', 'Wyoming']

States won by Penny : ['Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Georgia', 'Hawaii', 'Illinois', 'Indiana', 'Maine', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'New Mexico', 'New York', 'North Carolina', 'Ohio', 'Oklahoma', 'Pennsylvania', 'South Dakota', 'Texas', 'Virginia']

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!