Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROBLEM DEFINITION The student government presidential election of Bluegrass Com

ID: 3824667 • Letter: P

Question

PROBLEM DEFINITION The student government presidential election of Bluegrass Community and Technical College will be held soon. For reasons related to confidentiality, the chair of the election committee wants to computerize the voting. The chair is looking for someone to write a Python program to analyze the data and report the winner. Write a program to help the election committee. PROBLEM DETAILS The college has several departments. For the purpose of the election, each department on each campus manages its own voting process and directly reports the votes received by each candidate to the election committee. Therefore, the same candidate name is received with different number of votes from different departments. Input Keyboard input of candidate-name, department, number-of-votes sets for the candidates. Output Election results in a tabular form and the winner. The election committee wantstheoutput to look as follows (actual names and numbers will depend on the input the data in this table is only an example) Election Results Candidate Name Votes Total Alice in Wonderland 1,065 Balto 272 Donald Duck 51 Minnie Mouse 349 Pluto Tiger 1,242 Winnie the Pooh 548 Winner: votes Received by winner Total votes polled

Explanation / Answer

Answer

Solution

def getCandidateNmaeData():
data = []
name = input("Enter candidate-name: ")
department = input("Enter department: ")
votes = int(input("Enter Number-of-votes: "))
return [name, department, votes]

def getVotesdata():
votes = []
while True:
try:
votesmorethanone = int(input("Add votes data (1. Yes, 2. No?): "))
if (votesmorethanone != 1 and votesmorethanone != 2):
print(votesmorethanone)
print("Enter 1 or 2 only")
continue
elif votesmorethanone == 1:
votes.append(getCandidateData())
else:
return votes
except:
print("Enter 1 or 2 only")
continue

def electionResult(voting_data):
countVoting = {}
for data in voting_data:
if data[0] in countVoting:
countVoting[data[0]] += int(data[2])
else:
countVoting[data[0]] = int(data[2])
return countVoting

def getWinner(countVoting):
maxVotes = -1
winner = ""
for candidate in countVoting:
if countVoting[candidate] > maxVotes:
maxVotes = countVoting[candidate]
winner = candidate
return winner

def electionResultPrint(countVoting):
winner = getWinner(countVoting)
print(winner)
print("Election Results")# Print Enter Election Results
print("Candidate Name Votes Total") # Print Candidate Name and Votes total
print("-------------- -----------")#As per structure of output
for candidate in countVoting:
print(candidate, " ", "{:,}".format(countVoting[candidate]))
# print winner and votes recived bywinner
print("Winner: ", winner, " Votes Received by winner: ", "{:,}".format(countVoting[winner]))

voting_data = getVotesdata()
print(voting_data) # getting voting data
countVoting = electionResult(voting_data) # getting countVoting of Election result
electionResultPrint(countVoting) # print Election Result

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote