The worksheetDownload the PDF
Answers

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

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
    Answer: A. The information inside the brackets of a call is an argument. led is the function.
  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
    Answer: A. The brackets are what call a function. Without them nothing happens, and Python does not complain: one of the quiet mistakes.
  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()
    Answer: A, B. battery and distance answer with a number. led and stop tell the robot to do something.
  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
    Answer: A. An asking function is only useful if you do something with its answer, such as print it: print(battery()).
  5. [1 mark]In forward(50, distance=20), what is distance=20 called? (two words)

    Answer: named argument. An argument given as name=value is a named (or keyword) argument. The name says which piece of information it is.
  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
    Answer: A. The three arguments are red, green and blue, in that order, so the order of arguments matters.
  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
    Answer: A. The first argument is the frequency in hertz, the second is the length in seconds. The order of the arguments matters.
  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
    Answer: A. A function returns a value; a procedure carries out a task and returns nothing. Python calls both functions.

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:", ...)

The hint students can ask for: Set the LED first, then print the two sensor readings on their own lines, worded as the task shows. Nothing here needs the robot to move.

A solution

from bugbot import *
connect()
led('blue')
print('battery:', battery())
print('ahead:', distance())

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