Display the array of names and the array of votes to provide

Assignment Help Python Programming
Reference no: EM132356508

Question

Arrays must be used.

DO NOT use any Python pre-defined functions such as min, max, sum, etc.

We like to process some voting data.

a) Ask the user for the number of candidates in a local election. Use a try/except block to make sure the user does not enter a character or a floating point number as input. You need a loop to assure the user enters a valid whole number.

b) Given the number of candidates, ask for the user for last names of a series of candidates and the number of votes received by each candidate and store the data in 2 parallel arrays.

c) Validate the number of votes to make sure the number of votes is not a negative number. If a negative number is entered, the program must issue a message and continue to ask the user for a valid entry.

d) Write a function to display each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. The percentage value is calculated by dividing the number of votes by the total number of votes and multiplying the number by 100. The function accepts 2 arrays and the size of the array and displays the desired output. Make sure to display the percentage values to 2 digits after the decimal point.

e) Write a function that accepts the name of an output file and displays the array of names and the array of votes to the provided output file. Each record must be written on its own line. Note that the name of the file is entered in the main function and the value passed to the function along with the arrays to be displayed.

f) Write a function to return the name of the winner. DO NOT use a pre-defined Python function. The function accepts the array of names and votes, finds the minimum number of votes and returns the name associated with the minimum number of votes.

g) Write a function to return the name of the loser. DO NOT use a pre-defined Python function. The function accepts the array of names and votes, finds the maximum number of votes and returns the name associated with the minimum number of votes.

h) Write a function to sort the candidates by name. I just need the names in a sorted order. The function accepts an array of names and sorts the data. After the function is called, the data would be in alphabetical order. LOOK at the end of this document for a pseudocode for a function that sorts the data. ALL you have to do is to convert the pseudocode to Python code. Make sure to display the data in the sorted order.

i) Write a function that accepts as parameter the name of a candidate and return the number of votes received by the candidate. So, if the user enters Duck, the output will be 6000. Of course, if the given name does not exist, display an appropriate message.

FUNCTION sortData(array, arraySize)

Set flag = 0

While flag == 0

Set flag = 1

Set k = 0 While k <= (arraySize - 2)

If array[k] > array[k+1] then

Set temp = array[k]

array[k] = array[k+1]

array[k+1] = temp

set flag = 0

end if

set k = k + 1

end while(k)

end while(flag)

FUNCTION searchData(arrayName, arrayData, arraySize, searchItem)

Set found = 0

Set index = 0

While found == 0 and index < arraySize

If searchItem == arrayName [index] then

found = 1

index = index + 1

end while

if found == 1 then

return arrayData[index - 1]

else

return -99

End if

NOTE: The function either returns the number of votes or -99 when the name was not found. In the main function, we can use this return value in an IF statement to either display the number of votes or a message that the name is not found.

Reference no: EM132356508

Questions Cloud

How many times each letter of the alphabet was used : Allow the user to type in a sentence to allow the program to perform analytics. Find out how many times each letter of the alphabet was used in useras sentence.
Analyze a comma-separated values file of real estate data : Write a menu driven console program that loads, parses and analyzes a comma-separated values file of real estate data.
Display the stripped phone number : Ask the user to enter the 4-digit code of an orange. Strip all the leading and trailing whitespace characters from the code. Display the stripped phone number.
Write a program to analyze the test scores : An instructor teaches two classes this semester. Recently he gave the same test to both classes. Write a program to analyze the test scores.
Display the array of names and the array of votes to provide : Write a function that accepts the name of an output file and displays the array of names and the array of votes to the provided output file.
Identify and describe one federal public health law : Key Participants in Decision Making - Identify and describe one federal public health law and the key decision makers in getting the law passed
Write a python program to list the data types used in this : Write a Python program to load the exact data into a data frame df2016. Write a Python program to list the data types used in this data frame.
Describe the events that led us into war : Describe the events that led us into war despite the isolationist views. What lessons can be drawn from this experience for our modern day con cerns about war.
Why do people participate in religion : Why do people participate in religion? What were their motivations thousands of years ago? What are their motivations today?

Reviews

Write a Review

Python Programming Questions & Answers

  Write program that allows teacher to read in student names

Write program that allows teacher to read in student names. The program must be written in accordance with the following specs.

  Make a gui program that calculates the hypotenuse

Make a GUI program that calculates the hypotenuse of a right triangle after the user enters the lengths of the two short sides and clicks the Calculate button.

  Write an expression that concatenates the string

Write an expression that concatenates the String variable suffix onto the end of the String variable prefix .

  Ask from the user a string s, print a string

Ask from the user a string s, print a string where all occurrences of its first char have been changed to '*', except do not change the first char itself.

  Write a function which should accept a list argument

Write a function which should accept a list argument and an integer argument as input. The function should return a new list containing the k largest value.

  Design and implement a program that prints the number of odd

Design and implement a program that prints the number of odd, even, and 0 digits in an integer value that it reads from the keyboard.

  Write all the appropriate methods for the class

Create a Person class that contains the username, password, list of status updates, and list of friends. Write all the appropriate methods

  What is the distance of shortest path for the traveler

CS1081 Homework Assignment. A traveler is departing from point A toward point B with a constraint: What is the distance of shortest path for the traveler

  Convert a fahrenheit temperature to celsius

Convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions.

  Define a function that takes in a list of numbers

Define a function that takes in a list of numbers as an argument. Your function will iterate through the list with a for loop and return the smallest.

  Create a list that contains the months of the year

Create a list that contains the months of the year? Create a loop to print the month number and name? The response paper should be in APA format.

  Design and implementation of your demonstration system

ICT705 - Data and System Integration - University of the Sunshine Coast - write a report explaining the theory underlining the key concepts around the design

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd