Algorithms · GCSE · OCR J277 2.1.2, AQA 8525 3.1.1, Edexcel 1CP2 1.2.2 · about 15 min
Reading and writing your board's pseudocode, and translating it into Python.
[1 mark]What is pseudocode?
[1 mark]What is 17 MOD 5 in Python? Write the Python expression.
[1 mark]for i = 1 to 5 in OCR's Exam Reference Language. How many times does the loop run?
[1 mark]Which Python line is the same as AQA's x ← x + 1?
x = x + 1x == x + 1x <- x + 1x + 1 = x[1 mark]Which Python loop is the same as for i = 1 to 4?
for i in range(1, 5):for i in range(1, 4):for i in range(4):for i in range(0, 4):Translate the algorithm at the top of this lesson into Python, from the pseudocode for your board. The robot should step towards the wall in 10 cm steps while it is more than 30 cm away, then print whether it took an even or odd number of steps, in exactly the form even number of steps: 4.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() steps = 0
The hint students can ask for: Follow the pseudocode line by line: count the steps in a loop that runs while the wall is far enough away. At the end, test whether the count divides by two exactly to choose the message.
from bugbot import *
connect()
steps = 0
while distance() > 30:
forward(50, distance=10)
steps = steps + 1
if steps % 2 == 0:
print("even number of steps: " + str(steps))
else:
print("odd number of steps: " + str(steps))
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.