# In this challenge, you are tasked with helping a small, rural town ...

## Question

In this challenge, you are tasked with helping a small, rural town modernize its vote-counting process. (Up until now, Uncle Cleetus had been trustfully tallying them one-by-one, but unfortunately, his concentration isn\'t what it used to be.)
You will be give a set of poll data called election_data.csv. The dataset is composed of three columns: Voter ID, County, and Candidate. Your task is to create a Python script that analyzes the votes and calculates each of the following
The total number of votes cast
The percentage of votes each candidate won
The total number of votes each candidate won
The winner of the election based on popular vote.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import csv

# dictionary with candidates as keys and votes as values
candidates = dict()

with open("election_data.csv", mode="r") as csv_file:
for row in elections_data: # iterate over all rows
candidate = row[2] # candidate name
# if candidate name is not in the dictionary, update the dictionary
if candidate not in candidates.keys():
candidates.update({candidate:0})
# increment the number of votes by one
candidates[candidate] += 1

winner = max(candidates, key=lambda k: candidates[k])

# write results
file_to_output = "resultsPoll.txt"

with open(file_to_output, "w") as txt_file:
txt_file.write("Election Results...

By purchasing this solution you'll be able to access the following files:
Solution.zip and Solution.csv.

\$13.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.