1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
s344n2d4d5 [400]
3 years ago
7

Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes rece

ived by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is:

Computers and Technology
1 answer:
amm18123 years ago
4 0

Answer:

a= input("Enter the last name of first candidate: ")

aVotes= int(input("Enter Number of votes cast for "+ a + ": "))

b= input("Enter the last name of second candidate: ")

bVotes= int(input("Enter Number of votes cast for "+ b + ": "))

c= input("Enter the last name of third candidate: ")

cVotes= int(input("Enter Number of votes cast for "+ c + ": "))

d= input("Enter the last name of fourth candidate: ")

dVotes = int(input("Enter Number of votes cast for "+ d + ": "))

e= input("Enter the last name of fifth candidate: ")

eVotes = int(input("Enter Number of votes cast for "+ e + ": "))

votes= [aVotes,bVotes,cVotes,dVotes,eVotes]

aPercent= (round((aVotes/sum(votes))*100, 2))

bPercent= (round((bVotes/sum(votes))*100, 2))

cPercent= (round((cVotes/sum(votes))*100, 2))

dPercent= (round((dVotes/sum(votes))*100, 2))

ePercent= (round((eVotes/sum(votes))*100, 2))

print( a, ":", aVotes,"Votes", aPercent,"%")

print( b, ":", bVotes,"Votes", bPercent,"%")

print( c, ":", cVotes,"Votes", cPercent,"%")

print( d, ":", dVotes,"Votes", dPercent,"%")

print( e, ":", eVotes,"Votes", ePercent,"%")

winner= max(votes)

if winner==aVotes:

   print(a," is the Winner")

elif winner==bVotes:

   print(b," is the Winner")

elif winner==cVotes:

   print(c," is the Winner")

elif winner==dVotes:

   print(d," is the Winner")

elif winner==eVotes:

   print(e," is the Winner")

else:

   None

Explanation:

  • First section

<em> a= input("Enter the last name of first candidate: ") </em>

<em>aVotes= int(input("Enter Number of votes cast for "+ a + ": ")) </em>

<em>b= input("Enter the last name of second candidate: ") </em>

<em>bVotes= int(input("Enter Number of votes cast for "+ b + ": ")) </em>

<em>c= input("Enter the last name of third candidate: ") </em>

<em>cVotes= int(input("Enter Number of votes cast for "+ c + ": ")) </em>

<em>d= input("Enter the last name of fourth candidate: ") </em>

<em>dVotes = int(input("Enter Number of votes cast for "+ d + ": ")) </em>

<em>e= input("Enter the last name of fifth candidate: ") </em>

<em>eVotes = int(input("Enter Number of votes cast for "+ e + ": ")) </em>

Collects the last name and the number of  votes cast

  • Second section

<em>votes= [aVotes,bVotes,cVotes,dVotes,eVotes] </em>

<em />

places all the votes in a list.

The reason for this is to allow us use the "sum function" and "max function", to get the sum of all the votes.

  • Third section

<em>aPercent= (round((aVotes/sum(votes))*100, 2)) </em>

<em>bPercent= (round((bVotes/sum(votes))*100, 2)) </em>

<em>cPercent= (round((cVotes/sum(votes))*100, 2)) </em>

<em>dPercent= (round((dVotes/sum(votes))*100, 2)) </em>

<em>ePercent= (round((eVotes/sum(votes))*100, 2)) </em>

calculates the percentage of all the votes cast for the individual candidates

  • Fourth section

<em>print( a, ":", aVotes,"Votes", aPercent,"%") </em>

<em>print( b, ":", bVotes,"Votes", bPercent,"%") </em>

<em>print( c, ":", cVotes,"Votes", cPercent,"%") </em>

<em>print( d, ":", dVotes,"Votes", dPercent,"%") </em>

<em>print( e, ":", eVotes,"Votes", ePercent,"%") </em>

prints out the candidates name, number of votes received and the percentage

  • Fifth section

winner= max(votes)

gets the maximum votes cast

  • Sixth Section

if winner==aVotes:

   print(a," is the Winner")

elif winner==bVotes:

   print(b," is the Winner")

elif winner==cVotes:

   print(c," is the Winner")

elif winner==dVotes:

   print(d," is the Winner")

elif winner==eVotes:

   print(e," is the Winner")

else:

   None

uses if statements to compare the maximum votes with the votes gotten by all the candidates to get a winner

You might be interested in
This ingredient is often used as decoration for both hot and cold dessert​
soldier1979 [14.2K]

Answer: cream

Explanation: Cream This ingredient is often used as a decoration or accompaniment for both cold and hot desserts, but may also be used as one of the recipe ingredients.

Please mark as brainliest

8 0
2 years ago
Given two objects represented by the tuples (22, 1, 42, 10) and (20, 0, 36, 8):
Rudik [331]

Answer:

Given,

P = (22, 1, 42, 10)

Q = (20, 0, 36, 8)

a. Formula for Euclidean Distance :

distance = ((p1-q1)^2 + (p2-q2)^2 + ... + (pn-qn)^2)^(1/2)

Now,

distance = ( (22-20)^2 + (1-0)^2 + (42 - 36)^2 + (10-8)^2) ) ^(1/2)

=( (2)^2 + (1)^2 + (6)^2 + (2)^2 ) ) ^(1/2)

=(4+1+36+4)^(1/2)

=45^(1/2)

Distance = 6.7082

b.Manhattan distance :

d = |x1 - x2| + |y1 - y2|

d = |22- 20| + |1 - 0|

d = |2| + |1|

Explanation:

4 0
2 years ago
The Office ____ is a temporary storage area. Warehouse Clipboard Storehouse Gallery
yanalaym [24]
The answer is The Office Clipboard.

In most Microsoft Windows, Office Clipboard is used as a temporary storage for some software applications such as Microsoft Office Applications. It allows you to store up to 24 items either texts or graphics. For example, when you copy a text from one location this text will be temporarily stored in the clipboard until you paste them to another location.
4 0
3 years ago
Which type of operation writes the file system structure to the disk?
n200080 [17]
Formatting<span> writes the file system structure to the disk.</span>
8 0
3 years ago
Examine about the Internal &amp; External Fragmentation methods give an example for each. essay​
Tju [1.3M]

Internal Fragmentation occurs when a process needs more space than the size of allotted memory block or use less space. External Fragmentation occurs when a process is removed from the main memory. Internal Fragmentation occurs when Paging is employed. External Fragmentation occurs when Segmentation is employed.

3 0
3 years ago
Other questions:
  • ___ is the branch of computer science that explores techniques for incorporating aspects of intelligence into computer systems.
    5·1 answer
  • You're working at a large industrial plant and notice a tag similar to the one shown in the figure above. Which of the following
    5·1 answer
  • SOMEONE PLEASE HELP ASAP!!
    14·2 answers
  • John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastructure issues.
    12·1 answer
  • A ____ client locates all or most of the processing logic on the server.
    11·1 answer
  • What is the impact of information technology in your daily life?
    12·1 answer
  • A technician has been dispatched to a customer site to diagnose an issue where the computer turns off intermittently. Upon arriv
    11·1 answer
  • . Write at least three benefits of using a network.​
    8·1 answer
  • Which of the following makes Super Mario Run unique?
    6·1 answer
  • Which backup requires a small amount of space and is considered to have an involved restoration process?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!