The answersDownload the PDF
Worksheet

F1.3 Calling functions

Programming basics · GCSE · OCR J277 2.2.3, AQA 8525 3.2.10, Edexcel 1CP2 6.6.1 · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Arguments, telling and asking, and notes on the robot's buzzer.

Questions 8 marks in all

  1. [1 mark]In led("red"), what is "red" called?

    1. AAn argument
    2. BA function
    3. CA variable
    4. DA comment
  2. [1 mark]What happens when a program contains stop with no brackets?

    1. ANothing: the function is named but not called, and there is no error
    2. BThe robot stops
    3. CPython shows a SyntaxError
    4. DThe program ends
  3. [1 mark]Which of these functions ask the robot something and give back an answer?

    Tick every answer that is true.

    1. Abattery()
    2. Bdistance()
    3. Cled("red")
    4. Dstop()
  4. [1 mark]A program has the line battery() on its own. What does it show?

    1. ANothing: the answer comes back and is thrown away
    2. BThe battery percentage
    3. CAn error
    4. DThe word battery
  5. [1 mark]In forward(50, distance=20), what is distance=20 called? (two words)

  6. [1 mark]led(255, 0, 0) makes the LED red. What does led(0, 0, 255) make it?

    1. ABlue
    2. BRed
    3. CGreen
    4. DOff
  7. [1 mark]tone(440, 0.5) plays a note. What does the 0.5 set?

    1. AHow long the note lasts, in seconds
    2. BHow high the note is
    3. CHow loud the note is
    4. DWhich robot plays it
  8. [1 mark]battery() gives back a value and led("red") does not. In exam terms, which is a function and which is a procedure?

    1. Abattery() is a function, led("red") is a procedure
    2. Bbattery() is a procedure, led("red") is a function
    3. CBoth are procedures
    4. DBoth are variables

The task: lights and numbers

Make the LED blue, then print two lines: battery: <number> and ahead: <number>, using the robot's answers. The robot must not drive.

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

led("...")
print("battery:", ...)

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f1-3-calling-functions/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Flash the LED red, then green, then blue, one second each, then off.
  2. Print the distance, drive 10 cm, print the distance again.
  3. Play the first line of a tune you know. Middle C is 262 Hz, D 294, E 330, F 349, G 392, A 440, B 494.