The worksheetDownload the PDF
Answers

F1.9 Arithmetic operators

Programming basics · GCSE · OCR J277 2.2.1, AQA 8525 3.2.3, Edexcel 1CP2 6.5.1 · about 15 min

BugBotLab

What this lesson is about

The seven operators, integer division and remainder, and the order they work in.

Questions 11 marks in all

  1. [1 mark]What does this program print?

    print(20 / 5)
    Answer:
    4.0

    Dividing always gives a float, even when the answer is whole.

  2. [1 mark]What does this program print?

    print(10 // 4)
    print(10 % 4)
    Answer:
    2
    2

    // is whole-number division (4 goes into 10 twice) and % is the remainder (2 left over).

  3. [1 mark]What is the value of 2 + 3 * 4?

    Answer: 14. Multiply before add, as in maths: 3 * 4 is 12, plus 2 is 14.
  4. [1 mark]What is the value of (2 + 3) * 4?

    Answer: 20. Brackets first: 2 + 3 is 5, times 4 is 20.
  5. [1 mark]Which of these is a float?

    1. A4.0
    2. B4
    3. C-3
    4. D100
    Answer: A. A float has a decimal point. The others are integers, whole numbers.
  6. [1 mark]x % 2 is 0 when x is even. What is it when x is odd?

    1. A1
    2. B0
    3. C2
    4. Dx
    Answer: A. An odd number divided by 2 always leaves a remainder of 1.
  7. [1 mark]What does this program print?

    print(round(10 / 3, 2))
    Answer:
    3.33

    round with a second argument keeps that many decimal places.

  8. [1 mark]What is the value of 17 // 5?

    Answer: 3. Integer division: five goes into seventeen three whole times.
  9. [1 mark]What is the value of 17 % 5?

    Answer: 2. Modulus gives the remainder: 17 is 3 fives and 2 left over.
  10. [1 mark]What does this program print?

    print(2 * 3 ** 2)
    Answer:
    18

    Exponent before multiply: 3 ** 2 is 9, times 2 is 18.

  11. [1 mark]What does this program print?

    seconds = 135
    print(seconds // 60, seconds % 60)
    Answer:
    2 15

    135 seconds is 2 whole minutes, with 15 seconds left over.

The task: robot maths

Using only the numbers 17 and 5 in your calculations, print four lines: divide: 3.4, DIV: 3, MOD: 2 and power: 25 (the power is 5 to the power 2). Work each one out with an operator; do not type the answers. The robot must not drive.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

print("divide:", 17 / 5)

The hint students can ask for: Use the same pair of numbers with each of the four operators, and print a labelled line for each. Remember which one throws the remainder away and which one keeps it.

A solution

from bugbot import *
connect()
print("divide:", 17 / 5)
print("DIV:", 17 // 5)
print("MOD:", 17 % 5)
print("power:", 5 ** 2)

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.