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 20:10
Assume that minutes is an int variable whose value is 0 or positive. write an expression whose value is "undercooked" or "soft-boiled" or "medium-boiled" or "hard-boiled" or "overcooked" based on the value of minutes. in particular: if the value of minutes is less than 2 the expression's value is "undercooked"; 2-4 would be a "soft-boiled", 5-7 would be "medium-boiled", 8-11 would be "hard-boiled" and 12 or more would be a "overcooked".
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
This question involves a class named textfile that represents a text file. public class textfile { private string filename; private string filename; private arraylist words; // constructors not shown // postcondition: returns the number of bytes in this file public int filesize() { } // precondition: 0 < = index < words.size() // postcondition: removes numwords words from the words arraylist beginning at // index. public void deletewords(int index, int numwords) { } // precondition: 0 < = index < = words.size() // postcondition: adds elements from newwords array to words arraylist beginning // at index. pub lic voidaddwords(int index, string[] newwords) { } // other methods not shown } complete the filesize() method. the filesize() is computed in bytes. in a text file, each character in each word counts as one byte. in addition, there is a space in between each word in the words arraylist, and each of those spaces also counts as one byte. for example, suppose the words arraylist stores the following words: { mary had a little lamb; its fleece was white as snow. } the filesize() method would compute 4 + 3 + 1 + 6 + 5 + 4 + 6 + 3 + 5 + 2 + 5 as the sum of the lengths of each string in the arraylist. the value returned would be this sum plus 10, because there would also be 10 spaces in between the 11 words. complete the filesize() method below: // postcondition: returns the number of bytes in this file public int filesize() { }
Answers: 1
question
Computers and Technology, 24.06.2019 15:40
In the above figure, what type of cylinder arrangement is shown in the figure above? a. l-type b. v-type c. in-line d. horizontal pls make sure its right if its rong im grounded for 3months
Answers: 1
question
Computers and Technology, 25.06.2019 00:40
Roger ginde is developing a program in supply chain management certification for managers. ginde has listed a number of activities that must be completed before a training program of this nature could be conducted. the activities, immediate predecessors, and times appear in the accompanying table: activity immediate predecessor(s) time (days) a -− 44b -− 55 c -− 11 d b 1010 e a, d 55 f c 55 g e, f 1010 calculate the slack time. show the details.
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
Mathematics, 16.10.2020 16:01
question
English, 16.10.2020 16:01
question
Mathematics, 16.10.2020 16:01
question
Geography, 16.10.2020 16:01
question
Mathematics, 16.10.2020 16:01
question
Mathematics, 16.10.2020 16:01
Questions on the website: 13722362