Menu

(Solved) : Lab Description Lab Use Lists List Operations Process Election Results Declare Winner Anno Q37166137 . . .

Lab description: In this lab you will use lists and list operations to process election results and to declare a winner or anThe program will then process the vote count, and once the data is tabulated, it should announce the election results. ThereRequirements You must observe the following requirements in designing and developing your program: You must read the file andYou will then pass the vote_totals list to the function sort_2D(), provided for you below This function will return the listAutoSaveOn File Home Insert Page Layout Formulas Data Review View Help Tell me what you want to do votes1 (1)-Excel General CAutoSave(. Off File Home Insert Page Layout Formulas Data Review ViewHelp Tell L votes2 (1) Excel Conditional Fo -111 GeneraLab description: 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): Candidates District 1 Votes District 2 Votes District 3 Votes District 4 Votes Total Votes 156 417 265 130 97 62 21 143 0 176 127 116 509 190 80 212 678 78 Candidatel Candidate2 Candidate3 Candidate4 Candidate5 Candidate6 31 75 402 298 234 102 825 747 816 1136 358 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 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%) Candidate 1 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%) Candi date3 received 247 votes (5.37%) Candidate I received 215 votes (4.67%) Requirements 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: index 0 (candidate) index 1 (vote total) 825 747 816 1136 358 You will then pass the vote_totals list to the function sort 2D(), 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: index 0index 1 You will then pass the vote_totals list to the function sort_2D(), 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: 2 of 4 index 0index 1 5 1136 825 816 747 358 6 def sort 2D(vlist): return sorted(vlist, key lambda x: x1), reverse-True) 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 AutoSaveOn File Home Insert Page Layout Formulas Data Review View Help Tell me what you want to do votes1 (1)-Excel General Calibri Conditional Format as Formatting Table Sty Paste Merge & Styles Font Clipboard POSSIBLE DATA LOSS Some features might be lost if you save this workbook in the comma- delimited (esv) format. To preserve these foatures, save it in an Excel file A1 31 509 5621 5 190 417 143 80 265 298 212 130 176 0 402 97 127 678 78 234 102 116 62 6 10 12 13 14 15 16 17 18 19 20 votes1 (1) AutoSave(. Off File Home Insert Page Layout Formulas Data Review ViewHelp Tell L’ votes2 (1) Excel Conditional Fo -111 General ,IA” A” Calibri Format as Tab Cell Styles . s-% , Paste LE Alignment Styles Number ri Font Clipboard Some features might be lost if you save this workbook in the comma-delimited (csv) format i POSSIBLE DATA LOss these features, save it in an Excel file format. A1 21 143 0 76 927 116 54 109 104 80 112 678 31 75 102 98 834 102 65 130 497 62 10 Show transcribed image text Lab description: 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): Candidates District 1 Votes District 2 Votes District 3 Votes District 4 Votes Total Votes 156 417 265 130 97 62 21 143 0 176 127 116 509 190 80 212 678 78 Candidatel Candidate2 Candidate3 Candidate4 Candidate5 Candidate6 31 75 402 298 234 102 825 747 816 1136 358 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
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%) Candidate 1 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%) Candi date3 received 247 votes (5.37%) Candidate I received 215 votes (4.67%) Requirements
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: index 0 (candidate) index 1 (vote total) 825 747 816 1136 358 You will then pass the vote_totals list to the function sort 2D(), 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: index 0index 1
You will then pass the vote_totals list to the function sort_2D(), 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: 2 of 4 index 0index 1 5 1136 825 816 747 358 6 def sort 2D(vlist): return sorted(vlist, key lambda x: x1), reverse-True) 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
AutoSaveOn File Home Insert Page Layout Formulas Data Review View Help Tell me what you want to do votes1 (1)-Excel General Calibri Conditional Format as Formatting Table Sty Paste Merge & Styles Font Clipboard POSSIBLE DATA LOSS Some features might be lost if you save this workbook in the comma- delimited (esv) format. To preserve these foatures, save it in an Excel file A1 31 509 5621 5 190 417 143 80 265 298 212 130 176 0 402 97 127 678 78 234 102 116 62 6 10 12 13 14 15 16 17 18 19 20 votes1 (1)
AutoSave(. Off File Home Insert Page Layout Formulas Data Review ViewHelp Tell L’ votes2 (1) Excel Conditional Fo -111 General ,IA” A” Calibri Format as Tab Cell Styles . s-% , Paste LE Alignment Styles Number ri Font Clipboard Some features might be lost if you save this workbook in the comma-delimited (csv) format i POSSIBLE DATA LOss these features, save it in an Excel file format. A1 21 143 0 76 927 116 54 109 104 80 112 678 31 75 102 98 834 102 65 130 497 62 10

Expert Answer


Answer to Lab description: In this lab you will use lists and list operations to process election results and to declare a winner …

OR