The worksheetDownload the PDF
Answers

F5.1 What an algorithm is

Algorithms · GCSE · OCR J277 2.1.2, AQA 8525 3.1.1, Edexcel 1CP2 1.2.1 · about 12 min

BugBotLab

What this lesson is about

Inputs, processes and outputs; what makes an algorithm precise; programs implement algorithms.

Questions 5 marks in all

  1. [1 mark]What is an algorithm?

    1. AA set of step-by-step instructions to solve a problem
    2. BA program written in Python
    3. CA type of computer
    4. DA list of variables
    Answer: A. An algorithm is the method. A program is that method written in a language a computer can run.
  2. [1 mark]"Drive towards the wall and stop when close." What is wrong with this as an algorithm?

    1. AIt is ambiguous: towards and close are not precise
    2. BIt is too short
    3. CIt has no loop
    4. DNothing is wrong
    Answer: A. Every step must mean exactly one thing: how fast, and how close is close?
  3. [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. AThe number of sides
    2. BThe angle
    3. CThe shape driven
    4. DThe message printed
    Answer: A. Only the number of sides comes in. The angle is processing; the shape and the message are outputs.
  4. [1 mark]What does it mean for an algorithm to be finite?

    1. AIt always finishes
    2. BIt uses few variables
    3. CIt only works on small numbers
    4. DIt has exactly one loop
    Answer: A. An algorithm must end, rather than run forever.
  5. [1 mark]In which forms can an algorithm be written?

    Tick every answer that is true.

    1. AA flowchart
    2. BPseudocode
    3. CProgram code
    4. DA trace table
    Answer: A, B, C. A trace table follows an algorithm to check it; it does not describe the algorithm.

The task: any shape from an answer

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.

A solution

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.