The worksheetDownload the PDF
Answers

F6.6 The IDE

Robust programs · GCSE · OCR J277 2.5.2, AQA 8525 3.4.4, Edexcel 1CP2 6.1.5 · about 12 min

BugBotLab

What this lesson is about

Editors, error diagnostics, the run-time environment and the translator, in the cell you use.

Questions 4 marks in all

  1. [1 mark]Which are IDE tools listed by OCR?

    Tick every answer that is true.

    1. AEditors
    2. BError diagnostics
    3. CRun-time environment
    4. DTranslators
    Answer: A, B, C, D. All four are OCR's headings for IDE features.
  2. [1 mark]How does syntax highlighting help a programmer?

    1. AA missing quote or keyword stands out because the colours change
    2. BIt runs the program faster
    3. CIt fixes errors automatically
    4. DIt translates the code
    Answer: A. Colours show the parts of the code, so mistakes in structure are easy to see.
  3. [1 mark]What does stepping through a program in a debugger do?

    1. ARuns it one line at a time so values can be watched
    2. BDeletes lines with errors
    3. CCompiles it to machine code
    4. DSaves a copy
    Answer: A. Stepping shows exactly what each line does to the variables.
  4. [1 mark]Which IDE feature reports the line and type of an error?

    1. AError diagnostics
    2. BCode completion
    3. CFolding
    4. DLine numbers only
    Answer: A. Error diagnostics find errors and explain them, often before the program runs.

The task: use the diagnostics

This program should flash the LED three times, beeping each time, and then print flashed 3 times. It has a syntax error, a runtime error and a logic error. Use the squiggle, the error message and Debug to find and fix all three.

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

flashes = 0
for i in range(3)
    led("blue")
    tone(660, 0.1)
    wait(0.2)
    led("off")
    flashes = 1
print("flashed", flashs, "times")

The hint students can ask for: There are three faults: one is a missing punctuation mark that ends a header line, one is a name spelled differently from where it was made, and one sets a counter instead of adding to it. The error messages point at the first two.

A solution

from bugbot import *
connect()
flashes = 0
for i in range(3):
    led("blue")
    tone(660, 0.1)
    wait(0.2)
    led("off")
    flashes = flashes + 1
print("flashed", flashes, "times")

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