## 墨尔本大学COMP10001课业解析

• May 15, 2020

• 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”
Consider an electorate with 9 voters
Votes:[[“chris”, “nic”], [“marion”, “nic”], [“marion”, “chris”], [“nic”, “chris”],[“marion”, “nic”], [“nic”, ”chris”], [“nic”, “chris”], [“chris”, “nic”], [“marion”,“nic”]]
Number of votes for each candidate based on first preferences:“chris” : 2, “marion” : 4, “nic” : 3
No candidate with an absolute majority, “chris” has fewest first preferences.Reallocate second preferences from votes for “chris” to add to first preference votes for other candidates“marion” : 4 + 0, “nic” : 3 + 2
Winning candidate: “nic”

Candidates: “chris”, “marion”, “nic”
Consider an electorate with 6 voters
Votes:[[“chris”, “nic”], [“marion”, “nic”], [“marion”, “chris”], [“nic”, “chris”],[“chris”, “marion”], [“nic”, ”chris]]
Number of votes for each candidate based on first preferences:“chris” : 2, “marion” : 2, “nic” : 2