Ask Python Expert

Overview

In Project1, you were asked to create a Python program to decide a small election for the mythical country of Nerdvana. The method being used to decide that election was, essentially, first past the post voting. That is, the votes for each candidate are counted and the candidate with greatest number of votes wins the election. The only difference is that in the Nerdvana system the votes will be fractional.

For Project 2 you are to write a Python program to decide an election for a single seat under the Preferential Voting system used in the Western Australia Legislative Assembly (the Lower House). Similar systems are used for Lower House elections in most Australian states and for the House of Representatives in the Federal Parliament.

Background
The conduct of elections in Western Australia is governed by the Electoral Act of 1907. However, unless you are REALLY keen, you are better off looking instead at the Wikipedia entry for Instant Runoff Voting. In Australia, the system is known as Preferential Voting. Optional Preferential Voting is a variant of Preferential Voting that will also be relevant to this Project.

The main thing you need to know is that under Preferential Voting, for a vote to be "formal" an elector has to number all of the squares corresponding to candidates on the ballot paper. Squares are to be numbered from 1, corresponding to the most favoured candidate, followed by 2, for the next most favoured candidate, then 3 for the next most preferred after that, and so on, until all the squares are numbered. No number can be missed out. Thus, if there are 5 candidates, all of the numbers from 1 to 5 must be used (once only!). No other marks are allowed, e.g. ticks, crosses or other letters/symbols.
Deciding the Election

The following algorithm is used to decide who has won the election. The number of papers remaining after informal votes have been removed is the pool of "elegible votes".

1. In the first step, the first preferences from all the votes are counted. If a candidate secures at least 50% of the eligible votes, that candidate is declared elected and no further counting is done.

2. If no candidate has secured at least 50% of the elegible votes, the candidate with smallest tally is eliminated from further counting, and that candidate's second preferences are added to the counts of the remaining candidates.

3. If a candidate now has at least 50% of the vote, that candidate is declared elected. Otherwise, Step 2 is repeated: The candidate with smallest number of votes is eliminated and the next-preference votes redistributed among the remaining candidates. That is, for each vote associated with the eliminated candidate the current top preference (for the eliminated candidate) is removed and the next preference is instead associated with the next most favoured candidate. However, if the next most favoured candidate has also been eliminated, the preference is popped and the preference after that should be used, and so on. If all the preferences for a papers have been used, the vote is regarded as "spent", and discarded.

4. In the event of a tie for smallest count, the Act provides for the Returning Officer, i.e. person in charge of the count, to, first, recount and then, if the tie remains, to make a random choice among the candidates who have equal smallest counts. For this Project, however, please choose the candidate furthest down the list of candidates. (This provides reproducible behaviour when testing.)

Optional Preferential

Optional Preferential Voting is to also be modelled in this Project. Optional Preferential Voting is simply the voting method that allows incomplete ballots to be accepted, so long as at least one candidate receives a vote. In other words, if there are 5 candidates in the election for a seat, an elector can number, say, 3 squares, so long as no two squares have the same number and no numbers from 1 to 3 are missing.

Your Program
- Your program must contain a definition for the function main, starting with:

def main(candidates_file_name, ballots_file_name, optional=False):

As in Project1, main will be used to call your code during automated testing. However, in this case, the call to main will also be used to provide the file-name for the file of candidates names and the file-name of the file of ballots. Your program should therefore NOT call input().
- The file containing names of candidates is exactly as per Project1: one name per line.
- The votes, i.e. papers, will be in a comma separated file, e.g.
1,3,4,5,2 indicating that Candidate 1 has the first preference, Candidate 5 has the second preference, Candidate 2 has the third preference, etc. Other lines will look like:
2,1,3,5,4
1,3,4,5,2
3,5,2,4,1
1,4,5,2,3
If optional preferential voting is allowed, these votes are also formal:
2,1,3,,
,2,1,,3

Attachment:- Assignment.rar

Python, Programming

  • Category:- Python
  • Reference No.:- M92306474
  • Price:- $120

Guranteed 48 Hours Delivery, In Price:- $120

Have any Question?


Related Questions in Python

Part i the assignment filesone of the most important

Part I: The Assignment Files One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a ...

Homework -this homework will have both a short written and

Homework - This homework will have, both a short written and coding assignment. The problems that are supposed to be written are clearly marked. 1) (Written) Make heuristics Describe two heuristics for the slide problem ...

Tasksdemonstrate data scraping of a social network of

Tasks Demonstrate data scraping of a social network of choice. Develop technical documentation, including the development of the code & detailing the results. Provide a report on the findings, that includes research into ...

Assignment1 utilising python 3 build the following

Assignment 1. Utilising Python 3 Build the following regression models: - Decision Tree - Gradient Boosted Tree - Linear regression 2. Select a dataset (other than the example dataset given in section 3) and apply the De ...

Python programming assignment -you first need an abstract

Python Programming Assignment - You first need an abstract base class, called, Account which has the following attributes and methods: accountID: This attribute holds the ID assigned the account , if not provided set to ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Question research pythons dictionary data type dictdiscuss

Question : Research Python's dictionary data type (dict). Discuss its interface and usage. Include examples. Discuss practical applications of dictionaries.

Questionwhat is a python development frameworkgive 3

Question What is a python development framework? Give 3 examples python development framework used today. and explain which development framework is used in which industry.

Below zero - ice cream storethe local ice-cream store needs

Below Zero - ice cream store The local ice-cream store needs a new ordering system to improve customer service by streamlining the ordering process. The manager of the store has found that many orders are incorrect and s ...

The second task in this assignment is to create a python

The second task in this assignment is to create a Python program called pancakes.py that will determine the final order of a stack of pancakes after a series of flips.(PYTHON 3) Problem Task In this problem, your input w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As