Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python, a) Ask the user for the number of candidates in a local election. Use a try/except block to make sure the user does

In Python,
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 candidates 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 and the number of candidates, finds the maximum number of votes and returns the name
associated with the maximum 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 and the
number of candidates, finds the minimum 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. DO NOT use Pythons sort function if you know how to use it.
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.
Please include screenshot of code and the end results.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

8. Describe the steps in the development planning process.

Answered: 1 week ago