Question: do this in idle in python Aamir Carver Spencer Sparks MA 7 6 5 4 9 4 1 0 1 8 2 7 VA 4
do this in idle in python
Aamir Carver
Spencer Sparks
MA
VA
PA
OK
NY
The first line specify the number of candidates
The next lines specify the names of candidates: Aamir Carver and Spencer Sparks
The remaining lines specify information of votes for each state.
The first token MA VA PA OK NY specify the state abbreviation.
The second token specify the number of electoral votes in the state.
The remanding tokens specify the number of popular votes for each candidate. Each tokens represent for each candidate in the state. For example of the line MA in MA Aamir Carver has votes, and Spencer Sparks has votes. The number of votes of Spencer Sparks is more than Aamir Carver. Hence, Spencer Sparks wins electoral votes in MAPlace your code in a file named candidates.py
Here is a step by step guilelines:
Declare variables to hold:
A number of candidates.
A list of electoral vote counters for each candidate.
A list of candidate names.
Store information of votes into variables:
Use for loop to capture state and votes on each line.
Add the number of electoral votes to the candidate who has highest number of popular votes in the state
Print out the name of the candidate who wins the state
Determine the candidate who wins the overall election:
If more than one candidate that has highest number of electoral votes. Let's make this rule simple, the winner will be the candidate with lowest index.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
