subject

ALIGNMENT: The purpose of this assignment is to provide practice with reading data from a text file and using lists and loops to iterate through the data. You may find string functions like .split(“,”) to be helpful in parsing out the data being read. ASSIGNMENT: Student body elections were recently held with the following candidates on the ballot (shown here in Python lists!):

presCandidates = ["Alex Abernathy", "Brooklyn Bianco"]
vpCandidates = ["Chris Cortez", "Darcy Delaney","Emery Evans"]
secCandidates = ["Pat Peters", "Robin Ramirez", "Sam Smith", "Tracy Turner"]

A programming student had the brilliant idea of writing a program for students to vote on a computer and store their choices in a test file, whose format is each line representing the president, vice president, secretary voted for as a comma-delimited string. The text file looks like that shown below (except there are over 300 lines):

Brooklyn Bianco, Darcy Delaney, Pat Peters
Alex Abernathy, Emery Evans, Sam Smith
Alex Abernathy, Emery Evans, Sam Smith
Brooklyn Bianco, Chris Cortez, Sam Smith
Brooklyn Bianco, Chris Cortez, Tracy Turner
Brooklyn Bianco, Chris Cortez, Pat Peters
Alex Abernathy, Chris Cortez, Pat Peters
Alex Abernathy, Darcy Delaney, Robin Ramirez
Brooklyn Bianco, Emery Evans, Tracy Turner
But the student can’t figure out how to read the data into a Python program and have it tally the ballot and display the results. Can you help the student? The election. txt data file is available in the Canvas Assignment for downloading.

Write an original Python program that reads the data file and presents the results and use “def” functions: Many ways to do this, but here is my approach: Read the data file one line at a time (.readline()) in a while loop. I’d recommend removing the “\n” character a the end of the read string, and then split it by the comma (lookup the .split( ) string method. Split puts the items into a list). Then compare the result list item to the candidates; names and increment the appropriate variables (or items in an integer list) to keep track of votes received by each candidate. In the output, show the votes cast for each candidate and the total votes cast:

05C screen shot

Specifications & Tips:

Save your file with as “CIS156_05C_Election Results_YourLastName. py”
Print the project tile on the first line. Print the next line showing your name as the developer, followed by a blank line (remember you can use \n). Then provide a description of what the program does.
You are limited to using features discussed thus far in class or in the assigned readings/videos to date. Thus you may not use custom classes to solve the problem, but loops, conditional structures, variables, lists, string methods and read/write methods can all be used in your code.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:00
Our primary purpouse as electricians is to do wich of the following core concepts? a: install electrical components in a way they can be upgraded b: install electrical equiptment in a way that reduces heat c: install electrical systems in a safe manner d: only b and c
Answers: 1
question
Computers and Technology, 22.06.2019 09:40
In the lab, which of the following displayed a list of all installed services and included a description of the service, the current state, and whether the service started automatically or manually? a. the services manager b. the applications summary c. the recommended services d. list the safe services list
Answers: 2
question
Computers and Technology, 23.06.2019 05:20
Which operating system is a version of linux?
Answers: 1
question
Computers and Technology, 23.06.2019 20:50
3.11.3 quiz: comparing and analyzing function typesquestion 4 of 102 pointswhat can you say about the y-values of the two functions f(x) = 3x2-3 andg(x)=2* - 3?
Answers: 2
You know the right answer?
ALIGNMENT: The purpose of this assignment is to provide practice with reading data from a text file...
Questions
question
Social Studies, 29.04.2021 19:00
question
Mathematics, 29.04.2021 19:00
question
Mathematics, 29.04.2021 19:00
Questions on the website: 13722361