Create a python program to decide a small election

Assignment Help Python Programming
Reference no: EM131497739

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

Reference no: EM131497739

Questions Cloud

What is the conduct to which the doj objects : What is the conduct to which the DOJ objects? Why do they object to the conduct? Are conditions conducive to predatory behavior present in the airline industry?
What are the sources of long-run growth as envisioned : What are the sources of long-run growth as envisioned by the author in his early contributions? If so which potential technological revolution could make?
If it enters china should it allow users to be anonymous : Facebook in China? Introduction Seventy percent of Facebook's 500 million users were outside the United States, and Facebook was available in 70 languages.
Describe at least four points of a relevant economic article : Describe at least four key points of a relevant economic article from either the Strayer Library or a newspaper. The article must deal with any course concepts
Create a python program to decide a small election : Create a Python program to decide a small election for the mythical country of Nerdvana. The method being used to decide that election was.
Evaluate level of efficiency of technology implementation : HI5019 STRATEGIC INFORMATION SYSTEMS ASSIGNMENT - BUSINESS REPORT. Evaluate the level of efficiency of the technology implementation.
Identify issues and institutions associated with jet skis : Personal Watercraft, aka Jet Skis Personal watercraft, popularly known as water bikes or jet skis, are vessels powered by a jet pump with engines up to 135.
Make appropriate recommendations that might improve policies : Evaluate whether each item has enhanced or diminished your quality of life, and make any appropriate recommendations that might improve the policies.
Carry out a hypothesis test for chicken delights claim : A sample of 100 orders revealed that 84 of them were delivered. Using level of significance of 0.05, carry out a hypothesis test for Chicken Delight's claim.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd