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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:00, brooklynmikestovgphx
Suppose s, t, and w are strings that have already been created inside main. write a statement or statements, to be added to main, that will determine if the lengths of the three strings are in order by length, smallest to largest. that is, your code should determine if s is strictly shorter than t, and if t is strictly shorter than w. if these conditions hold your code should print (the boolean value) true. if not, your code should print false. (strictly means: no ties) example: if s, t, and w are "cat", "hats", and "skies" your code should print true - their lengths are 3-4-5; but if s, t, and w are "cats" "shirt", and "trust", then print false - their lengths are 4-5-5 enter your code in the box below
Answers: 2
image
Computers and Technology, 23.06.2019 01:10, brooklynneramos9956
Problem 1 - hashing we would like to use initials to locate an individual. for instance, mel should locate the person mark e. lehr. note: this is all upper case. generate a hash function for the above using the numbers on your telephone. you know, each letter has a number associated with it, so examine your telephone keypad. generate 512 random 3 letter initials and take statistics on a linked list array size 512 to hold this information report how many have no elements, 1 element, 2 elements, does this agree with the hashing statistics distribution?
Answers: 1
image
Computers and Technology, 24.06.2019 02:50, rurbanok12
Be sure to answer all parts. synthesize the following compound from benzene. a. b. c. d. e. f. reaction [1] conditions: a b c d e f reaction [1] product: draw structure reaction [2] conditions: a b c d e f reaction [2] product: draw structure reaction [3] conditions: a b c d e f reaction [3] product:
Answers: 3
image
Computers and Technology, 24.06.2019 12:30, nomood
Select all that apply. what two keys listed below should you use to enter data in an excel worksheet? tab backspace enter right arrow
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 in other subjects:

Konu
Mathematics, 18.08.2019 17:30
Konu
English, 18.08.2019 17:30
Konu
Mathematics, 18.08.2019 17:30