logo Use SA10RAM to get 10%* Discount.
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Ishanat TripathiTechnical writing
(5/5)

710 Answers

Hire Me
expert
Herbert BarciaEducation
(5/5)

835 Answers

Hire Me
expert
Rech ElleMathematics
(5/5)

586 Answers

Hire Me
expert
Debra StephensonBusiness
(5/5)

863 Answers

Hire Me
Linear Programming

Counting Votes Minnesota is holding elections on the day that this assignment is due!

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Problem B. (10 points)

Counting Votes Minnesota is holding elections on the day that this assignment is due!

We can help them count results by writing a program. Assume that each district copiles votes into a CSV file, where each row contains one citizen’s ballot data, and each column represents a different office up for election. The first row is header data indicating what office each column represents. For example, the CSV file above would represent a district with three offices up for election, and five citizens who voted.

The first voted for Jobu Tupaki for Mayor, Shallan Davar for Sheriff, and Buffy Summers for Governor. The second voted for Evelyn Wang for Mayor, Liz Lemon for Sheriff, and Leslie Knope for Governor. and so on…

We’re going to be creating a dictionary representing the vote counts for a specific office. For example, in the spreadsheet above, if I wanted a dictionary of vote counts for the office of County Sheriff, the result would be: {'Shallan Davar': 1, 'Liz Lemon': 3, 'Ron Swanson': 1} Whereas the vote counts for Governor would be: {'Buffy Summers': 2, 'Leslie Knope': 1, 'Gordon Freeman': 1, 'Monkey D. Luffy': 1} Write a function that count_votes(district, office) that takes in two strings as parameters. district should be the name of a file containing all voting data for a given district, in the format specified above. You can assume that said file actually exists (no need for a try-except block). office should be the name of one of the column titles present in the CSV file. You can assume that the office passed in will match one of the columns in the CSV file. The function should return a dictionary in which each key is a name present in the column corresponding to the given office, and the value represents how many times that name occurs within the column. Note that it is possible to have someone write in the same name for multiple different offices, so you do need to be careful to only count occurrences of the name present in the column representing the office you’re counting votes for. You are permitted to import the csv module, but this is not required. Hints: Be careful when the request is for the last column in the file - if you’re splitting by comma, then that column will contain the '\n' character, and this shouldn’t be included in the candidate names, or in the name of the office. You can assume for the sake of simplicity that no candidate or office will contain a comma in the name. Disclaimer: The data in the CSV files was randomly generated from all names available on the ballot for a given district according to https://myballotmn.sos.state.mn.us/ (along with a few fictional characters to simulate write-ins). Don’t take any given candidate randomly getting more “votes” than another as an endorsement. Examples (assumes that you have the sample files from hw09files.zip downloaded to the same directory that you’re running Python in): >>> count_votes('district_0z.csv', 'County Sheriff') {'Shallan Davar': 1, 'Liz Lemon': 3, 'Ron Swanson': 1} >>> count_votes('district_4b.csv', 'Mayor') {'Shelly Carlson': 7, 'Donna Meagle': 2, 'Kevin Nese Shores': 5} >>> count_votes('district_60b.csv', 'County Commissioner District 4') {'Angela Conley': 50, 'Monkey D. Luffy': 1, 'Jobu Tupaki': 2, 'Leslie Knope': 1}

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

421 Experts Online