ezAce

# 墨尔本大学COMP10001课业解析

• Second preference
• Multiple preferences (used in Australia)
First Past the Post• This is the simplest voting scheme.• There is a given list of candidates.• Each voter picks their preferred candidate.• We count the number of votes for each candidate.• The candidate with the most votes wins.• Example of a simple voting schemeCandidates: “chris”, “marion”, “nic”
Number of votes for each candidate:
“chris” : 121, “marion” : 399, “nic” : 180
Winning candidate: “marion”
First Past the Post• Example of a simple voting schemeCandidates: “chris”, “marion”, “nic”
Consider an electorate with 9 voters
List of votes:[“chris”, “marion”, “marion”, “nic”, “marion”, “nic”, “nic”, “chris”, “marion”] Number of votes for each candidate:“chris” : 2, “marion” : 4, “nic” : 3
Winning candidate: “marion”
• Note: winner might not have an absolute majority.i.e., less than 50% of the electorate voted for the winner• Note: an election can result in a tie, where two or more candidates have the highest number of votesCandidates: “chris”, “marion”, “nic”
Consider an electorate with 9 voters
Votes:[“chris”, “nic”, “marion”, “nic”, “chris”, “nic”, “nic”, “chris”, “chris”] Number of votes for each candidate:“chris” : 4, “marion” : 1, “nic” : 4
Winning candidate: “tie”
Question 1You need to write a function that returns the outcome of an election for a given list of votes using the First Past the Post voting scheme. Note: your function should use either a for loop or a while loop to count the votes.first_past_the_post(votes)votes: list of two or more strings, where each string corresponds to a vote for the candidate whose name is inthe string.Returns a string containing either the name of the candidate with the most votes using First Past the Post voting, or the string “tie” if there is a tie.You can assume that there is no candidate with the name “tie”.Example:v1 = [“chris”, “marion”, “marion”, “nic”, “marion”, “nic”,“nic”, “chris”, “marion”] first_past_the_post(v1)
returns “marion”
v2 = [“chris”, “nic”, “marion”, “nic”, “chris”, “nic”, “nic”,“chris”, “chris”] first_past_the_post(v2)
returns “tie”