Skip to main content
Skip to main content

There can
only be one

Years 7-8

Students write a simple suite of programs that can be used to facilitate an S.R.C. election though the collection and processing of data. It assumes that students have been introduced to Python programming language.



Learning hook


For an overview of this learning sequence download this PDF.

  1. Begin the lesson by explaining to students that we’re going to be writing a program that will allow us to determine the winner of a representative election – it could even be the election you run for student leaders at your school! But first, we need to understand the different ways that elections can occur. For that, watch the Counting your vote video from the Australian Electoral Commission.
  2. Depending on how you want to run the lesson, you may want to skip straight to the voting system explanations. However, it doesn’t hurt to give students a better understanding of the Australian democratic process anyway.

  3. After the video, discuss with students which voting system is used at your school when voting for student leaders. Why is that system used? Is it fair? How closely does it resemble one of the systems used in voting for the Australian parliament?
  4. Regardless of which system is used, one of the most important aspects of ensuring that an election is fair and appropriately conducted is to have a process for counting the votes accurately. When votes are collected using a secret ballot process on paper ballot forms, what are some of the potential issues? Have students come up with their own lists of issues and suggest possible solutions. They should include things such as:

    • Time consuming (use computers!)

    • Possible to miscount (have someone check each vote after it is counted; use computers!)

    • Potential for tampering with physical votes during counting (have multiple people check each vote
      Use computers!)

    • Have multiple people agree on the interpretation; use computers!)

  5. Ask the students to volunteer their issues. When they identify one, ask the group if they can think of a solution to the problem (possible solutions are listed above below each point as a guide). Students should identify that using a computer to count votes would solve most (if not all) of the issues they’ve identified. And that’s what we’re going to do!

Learning map and outcomes

Share the learning intentions for the activity. Tell students that the class will be:

  • identifying the requirements of our software so that it accurately counts votes and determines a winner using our chosen voting system

  • designing and implementing appropriate algorithms to allow us to automate the vote counting process

  • considering some of the issues and potential risks or problems our solution might introduce if it were to be adopted for larger, public elections.

Learners have a clear understanding of what they are learning and can see how it fits into the bigger context.

Learning input

Before they start defining their requirements, it is important students have completely understood the different voting systems being used.

The AEC Education site provides a resource called Topic 3 – What’s your vote worth? in their series on voting and elections. The introductory activity in this resource is an exploration of a hypothetical student election, and the associated worksheet is available as Topic 3 – Blackline Master 1 from the download link on the AEC Democracy Rules page.

Using the teacher guide for the introductory activity, have students work through BLM1 with particular emphasis on the secret ballot elections (ie one first past the post, the other preferential).

Over the course of this module, students will develop programs that correctly determine the winner of an election using two different types of voting systems:

  1. First past the post

  2. Preferential voting

Implementation of the first past the post solution will give them an opportunity to familiarise themselves with the implementation of an algorithm based on a relatively simple set of requirements.

From there, students who develop confidence working with Python and with algorithm design can independently pursue development of the preferential algorithm, while support may be necessary to have other students develop an appropriate solution.

Learning construction

  1. Explain to students that for the purposes of our program, the votes will have already been cast by voters and that the data has been stored in a comma separated text file, where each line represents a single vote with candidates listed in order of preference. Votes have been de-identified already so we don’t need to worry about that stage – we are simply going to use the data stored in the text file to work out who the winner of the election is.

  2. Tell students that their first task is to break down the steps that a program will need to perform to determine the winner in a 'first past the post' style election.


    • One easy way to represent the steps involved is to use a flowchart. Have them produce their flowchart on paper with a pencil (so it can be easily changed) in landscape orientation.

    • They need to think very carefully about what the program needs to do, and try to be as explicit about each step as possible. You may want to consider giving them the 'starter' flowchart provided, but make it clear to them that they will need to provide more detail for it to be useful. 

  3. Consider walking them through the following process as a guide. 
    Tell them:


    1. 'There are a lot of assumed steps missing from the flow chart. Let’s have a think about what’s missing from the part where we read from the file.

    2. At no point do we specify that we are going to be reading the file a line at a time (which makes sense since each vote is on a single line). Let’s add that, and change our loop slightly so that we repeat the part where we read a line, then check to see if it is the end of the file.

    3. Next, we say that we will store the first preference in the votes list, but we don’t actually have a votes list yet, so we’ll make that at the start of the program.

    4. Before we can put the value in the list, we need to extract it from the line. This means that we have to split the line up at the commas, and then store the first value.

    5. When we store the vote, we’ll be appending it to the list so that it gets added to the other votes we have already seen.

    6. Now we’ve got a more clearly defined process for reading the contents of our file!'



    • They should then end up with something that looks more like the 'starter 2' flowchart. If they need suggestions about what other things need more detail, ask them how they will count the number of votes for each person, and how they will then work out which number of votes is the largest. Both of these things will need to be expanded.

    • There are going to be variations that students come up with that will still yield the correct result - there is no single 'perfect' answer. In the end though, it should provide detail similar to that presented in the 'final' flowchart provided.

    • Note that the final version is not the most efficient or 'best' solution (it doesn’t cope with a draw) so that’s an interesting point of discussion you can have with students when/if you show them this answer.

    • Your students might come up with a better algorithm, and you should encourage them to solve the draw problem (the solution requires adding the winner(s) to a list by matching all candidates who have the highest number of votes, then printing each winner’s name out).

  4. The final step is to convert their algorithm into code. The sample voting_fpp file provided shows you how the algorithm expressed as a flowchart is converted into Python code.


    • Have students start their .py file by writing out the steps of their algorithm as code comments in the appropriate order, then translating these into Python instructions.

    • A correctly formatted votes_FINAL sample file has also been provided, with the winner of the first past the post style election being Candidate Green.

  5. Students can then progress on to the preferential voting algorithm. Two sample flowcharts and solutions have been provided: First past post: Flowcharts and Preferential: Flowcharts


    • one set where the algorithm uses 'buckets' to count votes (which is most analogous to the actual method used to count votes) then redistribute them as candidates are eliminated

    • the other which tracks eliminated candidates and processes each vote independently every round.


    Both are acceptable approaches.

  6. As in the previous example, the provided algorithms do not cope with a draw, but this time this is even more important – draws in earlier rounds that are not dealt with properly can lead to different results, and you’ll see this in action by running the code provided.
    The fix to this is to ensure all candidates with the lowest vote are eliminated each round (not just one of them), and to check that if elimination of all candidates occurs in any round, the election should be declared a draw.

Resources: Refer to these Python files: Preferential: codeFirst past post: CodePreferential: code (buckets)

Learning demo

  1. When students have completed their own voting programs, have them come up with their own set of votes (ie their own votes.txt file) that they can share with other people in the class to test each other’s algorithms.


    • They should always get the same answer, even if their code is different.

    • When two students get different answers, the challenge then becomes working out whose algorithm is performing correctly, what the problems are with the incorrect one and how they can be corrected.

  2. As a final reflection and consolidation activity, ask them to write a 300–500 word response to this statement:

  3. The voting systems used in Australian elections at all levels of government can be defined in algorithmic terms, so the counting of votes can be performed easily and reliably using computer software. However, modern elections still take place using paper ballots and secret ballot boxes across the country, where people present physically to the polling place in their local community. What are some of the reasons, both technical and social, that might prevent Australia from moving to a fully online, electronic voting system?

  4. Have them share their responses with other students through either an online collaboration tool (such as Google Docs or Padlet), a Post-it thought wall or in small-group discussions. Compile a class list of possible reasons based on their responses.

Learning reflection

Students reflect on their learning in this activity using the Triangle-Circle-Square strategy where they:

  • Triangle: identify three important points they have discovered from the lesson (these can be about any aspect of the activity they choose)
  • Square: write down anything that 'squares' with their thinking (ie that they agree with). This might be a good way of consolidating their thinking around the merits and risks of voting electronically
  • Circle: what thoughts are still 'circling' in their head? Are there any questions they still have about either writing and implementing algorithms, or about voting generally?

You can use the responses from this activity to identify any areas that might need extra attention in future lessons, and to get a sense of how far students have progressed in their understanding.