Modulo

Working out a remainder

The modulo operator (%) will work out the remainder left over when one value goes into another:

mod7

This will print:

mod2

30 / 6 gives 0. Because 6 goes into 30 exactly 5 times there is no remainder; so 0 is printed.


mod1

This would output:

mod3

30 / 7 gives 2. Because 7 goes into 30 4 times (28) it leaves a remainder of 2.


To check if a number is odd or even you can see if it leaves a remainder when divided by 2:

mod4

If you enter an even number (remainder of 0):

mod6

If you enter an odd number (remainder of 1):

mod5

Try this practice question out when you have tried inputs first:

Practice Task 1

Calculations not working? Tick off these common errors:

Have you saved a calculation into a variable?
Correct calculation symbols?
Have you printed the calculation?

< Back to Section Three