Algorithms · GCSE · OCR J277 2.1.2, AQA 8525 3.1.1, Edexcel 1CP2 1.2.1 · about 12 min
Inputs, processes and outputs; what makes an algorithm precise; programs implement algorithms.
[1 mark]What is an algorithm?
[1 mark]"Drive towards the wall and stop when close." What is wrong with this as an algorithm?
[1 mark]A program asks for a number of sides, works out the angle and drives the shape. Which are inputs?
Tick every answer that is true.
[1 mark]What does it mean for an algorithm to be finite?
[1 mark]In which forms can an algorithm be written?
Tick every answer that is true.
Turn the shape algorithm into a program. Ask How many sides? , work out the corner angle, drive the shape with 20 cm sides, and print drew a shape with <n> sides. The task answers 5. Work the angle out; do not type it.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # 1. Ask how many sides. # 2. Work out the angle. # 3. Repeat for each side: drive 20 cm, turn. # 4. Say how many sides were drawn.
The hint students can ask for: Ask how many sides and make it a whole number. The turn at each corner is a full turn shared between the sides. Then repeat drive-and-turn once per side.
from bugbot import *
connect()
sides = int(input("How many sides? "))
angle = 360 / sides
for i in range(sides):
forward(60, distance=20)
turn_right(30, angle=angle)
print("drew a shape with", sides, "sides")
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.