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, 24.06.2019 13:00
Append and make table queries are called queries. select complex simple action i think action
Answers: 1
question
Computers and Technology, 25.06.2019 07:30
What does the hard disk drive do? it stores all of the information on a computer. it controls a computer’s operating system. it enables visual interaction with a computer. it contains all of a computer’s internal parts.
Answers: 1
question
Computers and Technology, 25.06.2019 08:00
A( the heart of an information system, is a collection of all relevant facts organized in a series of integrated files.
Answers: 1
question
Computers and Technology, 25.06.2019 08:20
With technology, information is sent to users based on their previous inquiries, interests, or specifications.
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
Biology, 11.05.2021 05:40
question
Biology, 11.05.2021 05:40
question
Mathematics, 11.05.2021 05:40
Questions on the website: 13722367