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
6.10.1: Modify a C string parameter. Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley.
Andrej [43]

Answer:

#include <iostream>

#include <cstring>

using namespace std;

void replacePeriod(char* phrase) {

int i = 0;

while(*(phrase + i) != '\0')

{

if(*(phrase + i) == '.')

*(phrase + i) = '!';

i++;

}

}

int main() {

const int STRING_SIZE = 50;

char sentence[STRING_SIZE];

strcpy(sentence, "Hello. I'm Miley. Nice to meet you.");

replacePeriod(sentence);

cout << "Updated sentence: " << endl;

cout << sentence << endl;

return 0;

}

Explanation:

  • Create a function called replacePeriod that takes a pointer of type char as a parameter.
  • Loop through the end of phrase, check if phrase has a period and then replace it with a sign of exclamation.
  • Inside the main function, define the sentence and pass it as an argument to the replacePeriod function.
  • Finally display the updated sentence.
6 0
3 years ago
If you were at the front of a long line of people, stepped onto a chair and took a
WINSTONCH [101]
They are closer to the people and they work than a senior management
7 0
3 years ago
What kind of resources can we share over the network? Plzzzzzzzz help!!!!!!
lubasha [3.4K]

Sharing network resources requires abiding by certain constraints, as follows:

<span>Security: Organizations present ongoing opportunities for unauthorized shared resources. Security mechanisms should be implemented to provide efficient parameters.Compatibility: Various client-server operating systems may be installed, but the client must have a compatible OS or application to access shared resources. Otherwise, the client may encounter issues that create communication delays and requires troubleshooting.Mapping: Any shared OS hardware drive, file or resource may be accessed via mapping, which requires a shared destination address and naming conventions.<span>File Transfer Protocol (FTP) and File Sharing: FTP is not affected by shared resources because the Internet is FTP’s backbone. File sharing is an LAN concept.</span></span>
3 0
4 years ago
Read 2 more answers
HELP PLS!! Complete the following sentence.
Ymorist [56]
What the guy above me is true it’s high tech because it’s explaining what it is also.
4 0
3 years ago
A technically qualified individual who may configure firewalls and IDPSs, implement security software, diagnose and troubleshoot
sineoko [7]

Answer:

Security technician

Explanation:

Security technicians are responsible for fixing, planning, and implementing the IT and computer security system of organisations by making sure the safety and security of the data and information of the clients as well as the employees that make daily use of the systems

Security technicians administer security access to the clients and employees of the organization and are responsible for being up to date with the latest IT security technology developments.

7 0
3 years ago
Other questions:
  • list and briefly explain two other Discovery / inventions that were necessary for the eventual development of the technology nee
    12·1 answer
  • The answer for 1 and 2
    5·1 answer
  • The economist George gilder argued that
    6·1 answer
  • Let T be the statement: The sum of any two rational numbers is rational. Then T is true, but the following "proof is incorrect.
    14·1 answer
  • What devise did george stbitz contribute?
    13·1 answer
  • "The ______ of an operational system that supports an organization includes policies, requirements, and conditional statements t
    13·1 answer
  • Discuss the following
    14·1 answer
  • By convention only, either the first usable address or the last usable address in a network is assigned to the router (gateway)
    11·1 answer
  • Who do we make games for?(single term)
    15·2 answers
  • Assume you use Bubble Sort to sort a list with 15 elements (i.e.n= 9). Exactly howmany comparisons do you use (in the worst case
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!