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:

Get 20% Discount on This Paper
Pages (550 words)
Approximate price: -

Try it now!

Get 20% Discount on This Paper

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Custom Writings Help is a Quality-Oriented Company in Online Writing as a result of hiring exceptional professionals to execute clients' tasks.

Essays

Research Papers

At Custom Writings Help,We understand the struggle of research paper writing, and that is why at Custom WritingS Help, we are all out to help you. We pride ourselves on having a team of clinical writers. The stringent and rigorous vetting process ensures that only the 'BEST' Writers are chosen for the job. We have highly qualified Ph.D. and MA writers working with us; we equally offer these experienced writers specific bonuses and incentives to make them deliver highly original, unique, and informative content at reasonably low prices.

Admissions

Thesis Writing Service

Worlwide, Many Masters Students are struggling with Thesis Completion. A thesis is likely to be the longest and most challenging piece of work a student has ever completed. However, unlike essays and other assignments, a student can pick a particular interest topic and work on their initiative. Fortunately, we are there for you. At Custom Writings Help, you are assured of an authentic, imaginative, informative, linguistically great, and advantageous thesis that adheres to all your needs. So, why continue considering different writers when you have discovered the best in the field?

Editing

Custom Papers

Not a single student can avoid writing custom papers. However, a total lack of experience, skills, and time makes it very hard to produce a superb writing piece. Therefore, if you are seeking professional help, turn to us. Our specialized and experienced writers compose a variety of model papers, including custom essays, college term papers, research papers, book reports, MBA essays, executive summaries, dissertations, Ph.D. theses, admission essays, and research proposals for college and university students at any level.

Coursework

Essay Writing

Most of the students disregard the critical principles of essay writing and compose papers below sensible guidelines. Therefore, with Custom Writings Help, one should not worry about his/her essay. Our Writers compose informative and engaging content on all complexities and topics. We write meaningful and smart essays while prioritizing all aspects that bring about a good grade, such as impeccable grammar, proper structure, zero-plagiarism, and conformance to guidelines.

Coursework

Coourse Work Writing

Don't let the seemingly never-ending onslaught of writing assignments get you down. If you are looking where to get course work assistance online, the writers at Custom Writings Help are here to assist you with all of your writing needs. We undertake to unique delivery of papers that meet the professor's requirements. The content is proofread, edited, and checked plagiarism before submission to customers. No matter how big or small your work is, we will deliver on time. Try US Now! !

Coursework

Dissertation Writing Service

High-Quality Dissertation Writing Services are rare. They require Ph.D. academicians – not easily found. However, are an exception. The years, time, and resources we have invested in the dissertation world has given us a competitive advantage over others. Choose to come to Custom Writings Help; You will find perfect Ph.D. consultants who have written hundreds of dissertations theses ready to help you. Let our dissertation-writing services help you craft your dissertation, for you are assured we will give you the results.