CS12-04 Computer Science Watch
Arithmetic operators, DIV and MOD
In this lesson
Arithmetic operators, DIV and MOD: how to use the arithmetic operators +, -, *, / and exponentiation in code, work out integer division. AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Programming basics 4 of 9. More at https://scholafly.com
By the end: Use the arithmetic operators +, -, *, / and exponentiation in code, work out integer division (DIV, // in Python) and remainder (MOD, % in Python) for any two whole numbers including 11 DIV 2 = 5 and 11 MOD 2 = 1, say that ordinary division gives a real answer, and use MOD to test whether a number divides exactly (even or odd, every nth item).
What it covers
- 0:00 Intro: arithmetic operators
- 0:40 Arithmetic operators
- 1:56 Arithmetic operators: div and mod
- 4:29 Arithmetic operators: dIV and MOD as a pair
- 5:47 Arithmetic operators: mOD as a test
Key words
About this video
Arithmetic operators, DIV and MOD | GCSE Computer Science | CS12-04
Arithmetic operators, DIV and MOD: how to use the arithmetic operators +, -, *, / and exponentiation in code, work out integer division.
AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Programming basics 4 of 9.
More at https://scholafly.com
Watch first: CS12-02 - https://youtu.be/vAE8x16LgDE
Video code: CS12-04 (search "ScholaFly CS12-04")
#GCSEComputerScience #ProgrammingBasics #ArithmeticOperators
For teachers
This GCSE Computer Science lesson teaches arithmetic operators, DIV and MOD. By the end, students should be able to use the arithmetic operators +, -, *, / and exponentiation in code, work out integer division (DIV, // in Python) and remainder (MOD, % in Python) for any two whole numbers including 11 DIV 2 = 5 and 11 MOD 2 = 1, say that ordinary division gives a real answer, and use MOD to test whether a number divides exactly (even or odd, every nth item). It works through four worked examples and the mistakes examiners report.
Exam board specification references:
AQA 8525
- 3.2.3
Edexcel 1CP2
- 1.2.3
- 6.5.1
OCR J277
- 2.2.1
Read the transcript
A hundred and twenty-five people leave a cinema late at night, and each bus seats forty. How many buses should be booked? Ordinary division says three point one two five, and rounding to three leaves people on the pavement. The answer comes in two parts, full buses and people left over, and code has an operator for each. First, the familiar operators; the bus question gets its answer a little later.
An arithmetic operator is a symbol that does a calculation on two values. Add, subtract and multiply are written as a plus, a minus and a star. Ordinary division is a slash, and it always gives a real. Six divided by three, in Python, gives two point nought, not two. Raising to a power is two stars in Python, so two, star star, three is eight. One course's reference language writes a caret instead. In Python a caret does something different, with no error to warn you, and one course leaves powers off its list altogether. When a line holds several operators, code works them out in a fixed order. What does two plus three times four give in code? Fourteen. Times comes before plus, the same as in maths, so brackets are needed to get twenty.
Integer division, written DIV, gives how many whole times one number goes into another. The remainder is thrown away. Modulus, written MOD, gives the remainder: what is left over after those whole times. One course prints its own example: eleven DIV two is five, and eleven MOD two is one. Two goes into eleven five whole times, five twos make ten, and one is left over. That is three steps: how many whole times, multiply back, and what is left. In Python, DIV is written as two slashes and MOD as a percent sign. One course's reference language uses the words DIV and MOD themselves. DIV and MOD sit at the same level as times and divide in the order of operations. Now take seventeen and five: what are DIV, MOD and ordinary division? Three, two, and three point four. Five goes in three whole times, which makes fifteen, two is left over, and ordinary division keeps the decimal. Now swap them round: what are five DIV seventeen and five MOD seventeen? Nought and five. Seventeen is bigger than five, so it cannot fit in even once, and all of the five remains. One examiner's report, on a trace table question, says this. A common mistake was to complete a normal division instead of an integer division. The fix is a check you can see. The moment DIV appears, the answer is a whole number, so a decimal in your working means the wrong division was done.
DIV and MOD work as a pair whenever a total is split into whole groups and a remainder. Back to the cinema. A hundred and twenty-five DIV forty is three full buses. A hundred and twenty-five MOD forty is five people left over. How many buses must be booked, and why? Four. A remainder that is not nought means someone still needs a seat, so one extra bus goes on top of the three. Minutes into hours works the same way. Two hundred minutes DIV sixty is three whole hours. Now two hundred MOD sixty: how many minutes is that, beyond the hours? Twenty. Three sixties make a hundred and eighty, so twenty are left over: three hours and twenty minutes.
MOD has one more use: testing whether one number goes into another with nothing left over. Count from one to eight and take each number MOD two. The answers run one, nought, one, nought, all the way along, and every nought sits beside an even number. DIV two on the same numbers gives a different row altogether: nought, one, one, two, two, three, three, four. It says nothing about even or odd. So the test number MOD two equals nought is read in words as: the number divides exactly by two, which means it is even. How code compares two values is the job of the video Relational operators. One examiner's report, on a flowchart that tested a number with MOD, says this. Some students struggled to comprehend the relational test involving MOD, instead focusing on DIV, or whether the value divided by two had a remainder. The fix is to say the test in words every time it appears, divides exactly by two, before deciding what it does. Items are counted from one. Test A is count MOD five equals nought. Test B is count DIV five equals nought. Test C is count MOD five equals one. Which test picks out every fifth item: A, B or C? A. The fifth, tenth and fifteenth items leave no remainder at all. B is only True for items one to four. C picks the first, the sixth and the eleventh. One examiner's report notes this. Although the modulus function was not required in the solution, many responses included it in the calculation for determining when a line feed was needed in the output. A line feed is a new line on the screen. Those students used MOD by choice, to start a new line after every few values, which is the every fifth item test at work.
One division with two answers, the pair, and the test come back here, on numbers this video has not touched. What are twenty-three DIV four and twenty-three MOD four? Five and three. Four goes in five whole times, which is twenty, and three is left. A different kind: what does nine divided by three give in Python? Three point nought, a real. The slash always gives a real, however neatly it divides. Here's a test: what does number MOD two equals one tell you? The number is odd. Dividing it by two leaves one over. One more, at the cinema: ninety people, forty to a bus. How many buses? Three. Ninety DIV forty is two full buses, and ninety MOD forty leaves ten people, so one more bus.
If DIV and MOD make sense now, a thumbs up records this one as done. Otherwise, save the video, then work five pairs out by hand with a pencil; doing them is what makes them stick.
Next in the chapter: Relational operators. Hopefully that's next in your feed, but if not, search for ScholaFly C S twelve, oh five.
Every other video is on scholafly.com too, easy to search by video code or by keyword. Whatever you're revising, go there and have a look, or, watch the next video.
Related terms
For: AQA GCSE 8525, Edexcel GCSE 1CP2, OCR GCSE J277
On the specification
| Board | Spec | Statement |
|---|---|---|
| AQA GCSE 8525 | 3.2.3 | Use addition, subtraction, multiplication, real division and integer division including remainders. |
| Edexcel GCSE 1CP2 | 1.2.3 | Algorithms |
| Edexcel GCSE 1CP2 | 6.5.1 | Write programs using arithmetic operators, including modulus, integer division and exponentiation. |
| OCR GCSE J277 | 2.2.1 | Programming fundamentals |
For teachers
This GCSE Computer Science lesson teaches arithmetic operators, DIV and MOD. By the end, students should be able to use the arithmetic operators +, -, *, / and exponentiation in code, work out integer division (DIV, // in Python) and remainder (MOD, % in Python) for any two whole numbers including 11 DIV 2 = 5 and 11 MOD 2 = 1, say that ordinary division gives a real answer, and use MOD to test whether a number divides exactly (even or odd, every nth item). It works through four worked examples and the mistakes examiners report.