ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Arithmetic/DIV, MOD and useful patterns
J277 · 2.2.1

Unit 5 · Lesson 2

DIV, MOD and useful patterns

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Use DIV and MOD to calculate a quotient and remainder in ERL and Python.

DIV and MOD describe two parts of the same division. In 17 divided by 5, there are 3 complete groups with 2 left over, so 17 DIV 5 is 3 and 17 MOD 5 is 2. Python writes these operators as // and %. They are useful for splitting minutes into hours, grouping items and spotting odd/even patterns.

DIV

Integer division that returns the whole-number quotient and discards the remainder.

MOD

An operation that returns the remainder after division.

Quotient

The result of division; with DIV, only the whole-number part is returned.

Remainder

The amount left after making as many complete groups as possible.

Keep these in mind

  • ERL DIV maps to Python //.
  • ERL MOD maps to Python %.
  • A number MOD 2 gives 0 for an even number and 1 for an odd positive number.
  • For time conversion, DIV 60 gives whole hours and MOD 60 gives leftover minutes.

Learning objective

Use DIV and MOD to calculate a quotient and remainder in ERL and Python.

Exam tip

Translate the purpose before choosing an operator: complete groups need DIV; the amount left over needs MOD.

Common mistake

Do not swap DIV and MOD in a time conversion. totalMinutes DIV 60 is hours; totalMinutes MOD 60 is leftover minutes.

PreviousNext