☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

Remainders, decisions and averages

الأسبوع 2 · الدرس ١ «التفكير الحاسوبي وحل المشكلات» (٢): الزوجي والفردي والمتوسط · 3 دروس
1

Even or odd: the remainder idea

ICT Prep 3 Term 1, Unit 1, Lesson 1: pp. 8–9
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.

NumberRemainder after ÷ 2Kind
120even
191odd
331odd
400even
580even
711odd
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?
2
What does 24 % 2 give?
3
Can the remainder after dividing by 2 ever be 2?
4
Pencils are packed in boxes of 5. What is the remainder for 22 pencils?