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 3 candzdates 28 votes_00. txt
Here is the content of the votes_00.txt file
2
Aamix Carver
Spencer Sparks
MA 765494101827
VA 4424941909315
PA 81179896564695
OK 6420691758458
NY 42468648,2533608
The first line specify the number of candidates (2)
The next 2 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 (7,4,8,6,4) 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 765494101827], in MA, Aamir Carver has 65,494 votes, and Spencer Sparks has 101,827 votes. The number of votes of Spencer Sparks is more than Aamir Carver. Hence, Spencer Sparks wins 7 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, lower/upper cases, new line, etc.)
Spencex Spark wins 7 electoral votes in MA
spence: Spark wina 4 electozal Votes in VA
Aamix Carve wlns 8 electoral yotes in pA
Spencer Spark wirs 6 electorad votes 1 n ok
spencer spark wins 4 electoral yotes in Ny
The overa11 Winner is Spencef spark with 21 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.
Practice problems To run the program with file

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 Programming Questions!