GoalExplain even and odd numbers with the remainder and use % in Python.
New words
remainder · what is left over after a division that does not come out exactly% operator · the Python sign that gives the remainder of a divisioneven number · a number whose remainder is 0 when divided by 2odd number · a number whose remainder is 1 when divided by 2
Explanation
Share 8 sweets between two children: each gets 4 and nothing is left. Share 7 sweets: each gets 3 and one sweet is left over. The leftover is the remainder. A number is even when the remainder after dividing by 2 is 0, and odd when it is 1. Python has a sign for the remainder: %. So 7 % 2 gives 1 and 8 % 2 gives 0. Do not confuse it with the percent sign of maths: in Python % never means a percentage. The remainder is always smaller than the number you divide by, so after dividing by 2 only 0 or 1 can be left. This one idea lets a program decide whether any number is even or odd, which is the pattern part of the plan: the remainder after dividing by 2 tells the kind.
Number
Remainder after ÷ 2
Kind
12
0
even
19
1
odd
33
1
odd
40
0
even
58
0
even
71
1
odd
Worked examples
Python
1print(9 % 2)
2print(10 % 2)
Output
1
0
Adam has 9 stickers and shares them between 2 friends. Each friend gets 4 and one sticker is left, so the remainder is 1 and 9 is odd. With 10 stickers nothing is left, so 10 is even. Python gives the same answers.
Python
1print(17 % 5)
2print(15 % 5)
Output
2
0
The remainder works with other numbers too. Salma packs 17 pencils into boxes of 5. Three boxes are full and 2 pencils are left, so the remainder is 2. A remainder of 0 would mean that the pencils fit exactly.
Class activity
Choose six numbers of your own, two of them above 100. Make a table with the number, its remainder after dividing by 2, and the word even or odd. Check one of them by sharing that many sweets between two children on paper.
Practice
1
What is the remainder of 15 % 2, and is 15 even or odd?
The remainder is 1, so 15 is odd.
2
What does 24 % 2 give?
0, so 24 is even.
3
Can the remainder after dividing by 2 ever be 2?
No. The remainder is always smaller than 2, so it is 0 or 1.
4
Pencils are packed in boxes of 5. What is the remainder for 22 pencils?