The worksheetDownload the PDF
Answers

F5.2 Flowcharts

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

BugBotLab

What this lesson is about

The standard symbols, and turning a flowchart into code.

Questions 5 marks in all

  1. [1 mark]Which flowchart symbol is used for a decision?

    1. AA diamond
    2. BA rectangle
    3. CA rounded box
    4. DA slanted box
    Answer: A. A decision is a diamond with a Yes arrow and a No arrow.
  2. [1 mark]Which symbol is used for input or output?

    1. AA slanted box (parallelogram)
    2. BA diamond
    3. CA rectangle
    4. DA box with double sides
    Answer: A. Inputs and outputs use a parallelogram.
  3. [1 mark]In a flowchart, an arrow goes back up to an earlier decision. What does that become in code?

    1. AA while loop
    2. BAn if with no loop
    3. CA function
    4. DA comment
    Answer: A. Looping back to a decision repeats while the answer allows: a while loop.
  4. [1 mark]What is the box with double lines on its sides for?

    1. AA subroutine defined elsewhere
    2. BA decision
    3. CThe start of the flowchart
    4. DA variable
    Answer: A. It calls a subprogram, such as tone(note, 0.2).
  5. [1 mark]The rising scale flowchart starts with count = 0 and loops while count < 5, adding 1 each time. How many notes does it play?

    Answer: 5. count takes the values 0, 1, 2, 3 and 4 while the loop runs.

The task: the password guard

Turn this flowchart into a program. Ask for a password with the prompt Password? . While it is not bugbot, print wrong, beep, and ask again. When it is right, turn the LED green and drive forward 20 cm. The task types robot first, then bugbot.

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

password = input("Password? ")

The hint students can ask for: Ask once before the loop, then keep asking while the answer is still wrong, warning each time. Only after the loop does the robot unlock and drive.

A solution

from bugbot import *
connect()
password = input("Password? ")
while password != "bugbot":
    print("wrong")
    tone(220, 0.3)
    password = input("Password? ")
led("green")
forward(50, distance=20)

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