In this lab, you will use lists and list

  

In this lab, you will use lists and list operations to process election results and to declare a winner or announce a runoff. The vote information (number of votes each candidate receives in each district) must be read from a comma-delimited file named votes.csv. An example of the data and its format is given below: 31,509,156,21 75,190,417,143 402,80,265,0 298,212,130,176 234,678,97,127 102,78,62,116 The data above, shown in the bold outline below, should be placed into a two-dimensional list named votes. The list is interpreted as follows (shaded headers are not part of the data that will be read from the file, and are shown, along with the shaded italicized totals, for information only):

The program will then process the vote count, and once the data is tabulated, it should announce the election results. There are two possible outcomes:

Runoff – In the event that none of the candidates gets 51% of the vote (the example above, in file votes1.csv is such a case), a runoff between the top two vote-getting candidates is declared through the following output (note the decreasing order of vote-getters in both categories): No candidate attained 51% of the 4,599 votes cast, and a runoff will be held between: Candidate5 received 1,136 votes (24.70%) Candidate2 received 825 votes (17.94%) Other candidate vote totals: Candidate4 received 816 votes (17.54%) Candidate3 received 747 votes (16.24%) Candidate1 received 717 votes (15.59%) Candidate6 received 358 votes (7.78%)

Clear winner – If the top vote-getter wins more than 51% of the total vote, that candidate is declared the winner. Totals for other candidates are presented in decreasing order of votes received, as shown in the following output (example based on file votes2.csv): Candidate5 won the election with 2,936 votes out of 4,599 cast (63.84%) Candidate2 received 439 votes (9.55%) Candidate4 received 416 votes (9.05%) Candidate6 received 346 votes (7.52%) Candidate3 received 247 votes (5.37%) Candidate1 received 215 votes (4.67%)

Requirements: You must observe the following requirements in designing and developing your program:

You must read the file and load the votes list in the main() function.·

You must have a function get_vote_totals() that accepts the two-dimensional votes list, and returns a two-dimensional list that you will store in the variable vote_totals. This list has the candidate number at column index 0, and that candidate’s vote total at column index 1. Using the votes1.csv example data above (shaded headers are for information only and are not part of the list), the list would be:·

You will then pass the vote_totals list to the function sort_it(), provided for you below. This function will return the list sorted, in descending order, by the value at index position 1 (the total number of votes). Store the returned value in list variable sorted_votes. Using the data above, this sorted list returned is:·Write the remainder of the program so that it provides the election results output shown above.·

You may not use any global variables (global constants are permitted)·

Your program will be tested with multiple input files. It must handle both the Clear Winner and Runoff cases.·

data from votes1.csv:

data from votes2.csv:

Calculate Your Essay Price
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more