Programming basics · GCSE · OCR J277 2.2.1, AQA 8525 3.2.3, Edexcel 1CP2 6.5.1 · about 15 min
The seven operators, integer division and remainder, and the order they work in.
[1 mark]What does this program print?
print(20 / 5)
4.0
Dividing always gives a float, even when the answer is whole.
[1 mark]What does this program print?
print(10 // 4) print(10 % 4)
2 2
// is whole-number division (4 goes into 10 twice) and % is the remainder (2 left over).
[1 mark]What is the value of 2 + 3 * 4?
[1 mark]What is the value of (2 + 3) * 4?
[1 mark]Which of these is a float?
4.04-3100[1 mark]x % 2 is 0 when x is even. What is it when x is odd?
[1 mark]What does this program print?
print(round(10 / 3, 2))
3.33
round with a second argument keeps that many decimal places.
[1 mark]What is the value of 17 // 5?
[1 mark]What is the value of 17 % 5?
[1 mark]What does this program print?
print(2 * 3 ** 2)
18
Exponent before multiply: 3 ** 2 is 9, times 2 is 18.
[1 mark]What does this program print?
seconds = 135 print(seconds // 60, seconds % 60)
2 15
135 seconds is 2 whole minutes, with 15 seconds left over.
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.
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.