More Arithmetic Operators

Advanced Operators

Integer division tell you how many times the divisor fits completely into the dividend.

Modulo will give you the reminder after a division.

Think back to when you did maths at primary school, before you learnt about the decimal place....

When you were asked to do a calculation like 14 ➗3, you may have said the answer was 4 remainder 2.

The 4 in the example above is the result of an integer division - how many times 3 completely fits into 14.

In Python we use the operators:

    • // - integer division

    • % - The remainder of an integer division

The answers will always be integers.

Example

A taxi can only hold 7 passengers.

How many taxis are needed to drive 17 people to the airport?

If we divide 17 by 7 we would get 2.43, but you can't have 2.43 taxis.

If we do an integer division then we would get 2. You can have 2 taxis.

To discover if we need an additional taxi we would MOD 17 by 7 to see if there was a remainder. If there is, we would need an extra taxi.

The python code might look like this: