Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

2.4 (1 of 3): Arithmetic operators

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Sharing a pizza bill

Four friends share a 50 pound pizza bill. How much does each person pay? 50 divided by 4 is 12.5.

But they only have pound coins. Each friend puts in 12, and 2 pounds are left over to pay. A program must know how to say both things.

Key words

WordWhat it meansExample
OperatorA symbol that does something to values.+
Arithmetic operatorAn operator for maths.+ - * /
ExponentiationMultiplying a number by itself again and again. It is also called power.2 ** 3 is 2 x 2 x 2, which is 8
Integer divisionDivision that gives only the whole number part.7 // 2 is 3
ModulusThe remainder after a division.7 % 2 is 1
RemainderWhat is left over after sharing equally.7 shared by 2 leaves 1
FloatA number with a decimal point.12.5
IntegerA whole number.12

The cells students fill in are left blank in this preview.

Watch: the operators share the bill

Press Play on the short film below. It shares the pizza bill with /, // and %, then shows ** and two operators in one line.

Film: arithmetic operators, what each one is for

Arithmetic operators: what each one is for

Every scene, as text

  1. Four friends share a 50 pound pizza bill: print(50 / 4) shows 12.5, a float, a number with a decimal point. But they only have pound coins.
  2. Integer division gives only the whole number part: print(50 // 4) shows 12, the pounds each. Modulus gives the remainder after a division: print(50 % 4) shows 2, the pounds left over.
  3. Myth (false): % works out a share of 100. % is the remainder sign: 7 sweets shared by 2 friends leave 1, so print(7 % 2) shows 1, what is left over, not a part of anything.
  4. Check: 4 people times 12, plus the leftover. print(4 * 12 + 2) works out 4 * 12 first, which is 48, then adds 2, and shows 50.
  5. Myth (false): / gives an integer when it divides exactly. print(8 / 2) shows 4.0, because / always gives a float. For the whole number part, print(8 // 2) shows 4.
  6. print(2 * 3) shows 6, but exponentiation, also called power, is different: print(2 ** 3) shows 8, because 2 ** 3 is 2 x 2 x 2.
  7. With more than one operator, * comes before +: print(2 + 3 * 4) shows 14, as 3 * 4 is 12 first. Brackets come first of all: print((2 + 3) * 4) shows 20, as 2 + 3 is 5 first (a preview: lesson 2.9 has the full order).

Try it: the first four

Code: python
print(8 + 2)
print(8 - 2)
print(8 * 2)
print(8 / 2)

# Change the numbers and run again.
# Notice that 8 / 2 gives 4.0, a float.

Make a free account to save your work and track your progress.

The seven arithmetic operators

OperatorNameExampleResult
`+`Add`7 + 2`9
`-`Subtract`7 - 2`5
`*`Multiply`7 * 2`14
`/`Divide`7 / 2`3.5
`**`Exponentiation (power)`2 ** 3`8
`//`Integer division`7 // 2`3
`%`Modulus (remainder)`7 % 2`1

The cells students fill in are left blank in this preview.

Work it out

Have a go

Work it out

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Worked example: 50 shared by 4

QuestionOperatorCalculationAnswer
How much each, with a decimal?`/`50 / 412.5
How many whole pounds each?`//`50 // 412
How many pounds are left over?`%`50 % 42
Check: 4 people times 12, plus the leftover`*` and `+`4 * 12 + 250

The cells students fill in are left blank in this preview.

Integer division and modulus

Think about sharing sweets (small candies). 7 sweets, 2 friends. Each friend gets 3. One sweet is left.

7 // 2 gives 3: how many times 2 fits into 7. 7 % 2 gives 1: what is left. You can use them together to change minutes into hours and minutes.

Try it: minutes to hours

Code: python
total = 135

hours = total // 60
minutes = total % 60

print(hours, "hours", minutes, "minutes")

# 60 goes into 135 two times, so hours is 2.
# 135 - 120 leaves 15, so minutes is 15.
# Change total to 200.

Make a free account to save your work and track your progress.

More than one operator

You can use several operators in one line. Python works out what is inside brackets first.

So (2 + 3) * 4 is 20. The full order of operations has its own lesson.

Extra: Worked example: the order of work

ExpressionStep 1Step 2Answer
`2 + 3 * 4`3 * 4 is 122 + 1214
`(2 + 3) * 4`2 + 3 is 55 * 420
`10 - 4 / 2`4 / 2 is 2.010 - 2.08.0
`2 * 3 ** 2`3 ** 2 is 92 * 918
`7 + 7 // 2`7 // 2 is 3: // and % go with * and /7 + 310

The cells students fill in are left blank in this preview.

Match the operator to its job

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Your turn: use the operators

Use the right operator in four functions. hours_and_minutes turns 135 into 2 hours 15 minutes. It always writes the words hours and minutes, even for 1 hour. square multiplies a number by itself using the power operator. each_person_pays gives the whole pounds each person pays when a bill is shared. left_over gives the pounds that remain. Press Run Tests.

Code: python
def hours_and_minutes(total_minutes):
    # Text like: 2 hours 15 minutes. For 135 minutes.
    return None


def square(number):
    # A number times itself. Use the power operator.
    return None


def each_person_pays(total, people):
    # Share the total between people. Give back the whole pounds each person pays.
    return None


def left_over(total, people):
    # The pounds that are left after everyone pays the whole amount.
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

When to use each one

Tip

Use // and % for whole things: people, minutes, sweets. Use / for measurements. Use % to check if a number is even or odd: a number is even if it leaves no remainder when divided by 2.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Exit quiz

Have a go

Exit quiz

6 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Remember

Important

+ - * / ** // %. // is the whole part. % is the remainder. / always gives a float.

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.