Instructions: For this assignment, you will write a program that reads election data from a file and processes that data in several different ways, inlcuding writing a report to a different file.
Data File Format
Adams
6457
4385
Asotin
13632
8623
Benton
97849
68834

The election data we will work with is stored in a simple text file. Each line of the file contains one of 3 different things:
• a county name
• the number of registered voters in the county
• the number ballots counted for the last election (as of noon on November 9th, 2012 for the data file provided)
The file format is highly structured. County names are listed in alphabetical order. On the line after each county name is the number of voters registered in that county. On the next line is the number of ballots counted. This sequence is repeated for each county. The first few lines of the sample file are shown at right to illustrate this. Here is a link to the sample file: ElectionData.txt
Program Specification
Write a program that does the following:
• Allow the user to specify the name of an input file containing election data (that way, different data files can be tested).
• Read the data from the file and write a report out to a new file as follows:
o The name of the output file should be the name of the input file preceeded with the word ‘REPORT’. So, if the input file is named ‘election.txt’, then the output file should be named ‘REPORTelection.txt’. If the input file is named ‘returns.txt’, then the output file should be named ‘REPORTreturns.txt’.
o The report should include one line for each county in the data file. The line should list the name of the county followed by the percentage of registered voters who cast ballots. The percentage should be rounded to one place after the decimal point. Here is an example of what the first part of the output file would look like for the data shown above:
Adams 67.9%
Asotin 63.3%
Benton 70.3%

• Finally, show the following information in the Python shell window in a nicely-formatted, easy to understand report:
o the total number of county names listed
o the total number of registered voters in the state
o the total number of ballots counted
o the percentage of all registered voters whose ballots were counted
o the number of counties with less than 50% of registered voters casting ballots
o the percentage of counties with more than 80% of registered voters casting ballots
Development Tips:
1. Use a loop to read the data from the file and process the data. Only one loop is needed to do everything!
2. Use a counter to count the total number of county names.
3. Use counters along with ‘if’ statements inside the loop to count the number of counties with less than 50% or more than 80% of registered voters casting ballots.
4. Use accumulators to add up the number of registered voters and the total number of ballots cast.
5. Remember that counters and accumulators always need to be initialized before the beginning of the loop.
6. Plan your progam carefully on paper before you start writing code. Remember that you need to “process” the file one line at a time. You can’t “jump around” to get the info you need like you can do as a human reader. “Be the computer!”
7. Remember that a string value read from a file could have a ‘\n’ character at the end of it.
________________________________________
Testing — Be sure to carefully test your program with different files. You can create a simple, short file to make testing easy. As always, be sure to document your testing in comments at the end of the program. Your comments should also say if you think any part of the assignment requirements have not been met.
________________________________________
Grading
/12 correctly determines 6 quantities to be shown in the shell window: # counties, # registered voters, # ballots counted, percentage of voters who cast ballots, [removed]80% counties
/10 reads and writes files properly (reads data, writes out a report file, closes files, no errors)
/3 documented test cases
/5 proper comments; good variable names; declarations; indenting; blank lines

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed with your coursework?
Get quality coursework help from an expert!