The purpose of the Project is to to complete the audit using Python and to print the results to the Command Line also, to save it to a Text File.
The requirenebts to complete the audit are:
- Calculate the total number of votes cast.
- Get a complete list of candidates who received votes.
- Calculate the total number of votes each candidate received.
- Calculate the percentage of votes each candidate won.
- Determine the winner of the election based on popular vote.
- The voter turnout for each county.
- The percentage of votes from each county out of the total count.
- The county with the highest turnout.
The project was created using next resources:
- Data Source: election_results.csv which be found in the Resources
- Software: Python 3.9.6, Visual Studio Code 1.58.0
Full audit results can be found in the Analysis folder.
The election analysis shows 369,711 total votes.
The Candidates were:
- Charles Casper Stockham;
- Diana DeGette;
- Raymon Anthony Doane.
The Candidate results were:
- Charles Casper Stockham received 23% of the votes and 85,213 votes;
- Diana DeGette received 73.8% of the votes and 272,892 votes;
- Raymon Anthony Doane received 3.1% of the and with 11,606 votes.
The Counties were:
- Denver;
- Jefferson;
- Arapahoe.
The County vote results were:
- Jefferson County received 10.5% of the votes with 38,855 votes;
- Denver County received 82.8% of the votes with 306,055 votes;
- Arapahoe County received 6.7% of the votes with 24,801 votes.
The winner of the election:
- Diana DeGette, who received 73.8% of the votes and 272,892 number of votes;
The county with the largest voter turnout:
- Denver county, which received 82.8% of the votes with 306,055 votes.
This script could be used for any election with some easy script modification and additional data.
For instance, with added data it can be used to get result of budget, age, sex of candidates and so on. To analyse "budget" modification is place of counties by changing the index and renaming related variable. The change should be here:
Additionally, the script can be modified to select winner candidates in each county. A pseudocode of modification can be following: loop through counties and candidates with condition such as: if the most popular candidate in a county then add to a new dictionary of county with candidate. Then, print results or print a winner as the most popular candidate in county by comparing elements of dictionary. The code should be modified in part of loop with condition in the attached screen:
and here modified or aded: