Question: Practice problems To run the program with file argument: $ python 3 candzdates 2 8 votes _ 0 0 . txt Here is the content
Practice problems
To run the program with file argument:
$ python candzdates votes txt
Here is the content of the votestxt file
Aamix 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 MA
Here is an example of the expected output if we use votes o txt input file: Your output must be exact same as expected output below such number of spaces, lowerupper cases, new line, etc.
Spencex Spark wins electoral votes in MA
spence: Spark wina electozal Votes in VA
Aamix Carve wlns electoral yotes in pA
Spencer Spark wirs electorad votes n ok
spencer spark wins electoral yotes in Ny
The overa Winner is Spencef spark with electoral votes
Please only modify the implementation inside the blocks below:
EILI UP YOUR CODE BEIOM THIS LINE
# PILT UP YOUR CODE ABOVE THIS LINE
Here is a step by step guilelines:
Declare variables to hold:
A number of candidates.
A ist 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 yotes 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
