Drop links or images here to add them to the editor.

In this topic students learn two more arithmetic operators: modulo (%), which gives the remainder after division, and exponentiation (**), which raises a number to a power.

Learning objectives and goals

Be able to read, comprehend, trace, adapt and create Python code that:

Slide deck

This chapter was written for Dodona from new material by the course author, after the rest of the course had been converted, so it has no deck of its own. The author’s Intermediate Python series has a Numbers deck that covers the modulo half of this chapter with different examples; it does not mention exponentiation at all: on Google Slides. A PDF copy is kept on Dodona too.

Teacher notes

This chapter extends the Calculations chapter. Both operators appear in that chapter’s operator table as well, so a class that skips this series still meets them; this series is where they are practised. They are here because the exam specification lists them alongside the other arithmetic operators, and the earlier chapter did not cover them.

Modulo is the one that needs the teaching. Students know division and they know remainders from primary school, but they rarely connect the two, and the % sign itself suggests percentages. The most useful framing is that // and % are a pair that answer the two halves of one question: how many whole groups, and how many left over. Every task in this series that uses % can be read that way: sweets shared between people, energy into batteries, seconds into minutes, cupcakes into boxes.

Exponentiation is straightforward once students have seen that ** is the typed form of a raised power. It is worth pointing out that one star and two stars mean different things, because 2 * 4 and 2 ** 4 look alike and give 8 and 16.

The series comes before selection, so the classic use of modulo, testing whether a number is even with if number % 2 == 0, is shown on the theory page as a calculation only. It is worth returning to once the selection chapters have introduced if.

Key points

Errors and misconceptions