The answersDownload the PDF
Worksheet

F2.2 Selection: if

Decisions and loops · GCSE · OCR J277 2.2.1, AQA 8525 3.2.4, Edexcel 1CP2 6.5.2 · about 12 min

BugBotLab
NameClassDate

What this lesson is about

Relational operators, and a block that runs only when a condition is true.

Questions 9 marks in all

  1. [1 mark]What does this program print?

    speed = 40
    if speed > 50:
        print("fast")
    if speed > 30:
        print("medium")
    if speed > 10:
        print("slow")
    print("checked")
  2. [1 mark]What is the difference between = and ==?

    1. A= stores a value, == asks whether two values are equal
    2. BThey mean the same
    3. C== stores a value, = compares
    4. D= is for text, == for numbers
  3. [1 mark]Which comparison means "is not equal to"?

    1. A!=
    2. B<>
    3. C=!
    4. Dnot=
  4. [1 mark]What does this program print?

    d = 25
    print(d < 30)
    print(d >= 30)
  5. [1 mark]What happens to the block under an if when the question is False?

    1. AIt is skipped, and the program carries on below it
    2. BIt runs anyway
    3. CThe program stops
    4. DPython shows an error
  6. [1 mark]What does this program print?

    x = 7
    if x % 2 == 0:
        print("even")
    print("done")
  7. [1 mark]What does this program print?

    answer = "Yes"
    if answer == "yes":
        print("driving")
    print("done")
  8. [1 mark]d is exactly 40. Which condition is True?

    1. Ad <= 40
    2. Bd < 40
    3. Cd > 40
    4. Dd != 40
  9. [1 mark]How does AQA pseudo-code write "is equal to"?

    1. A=
    2. B==
    3. C===
    4. DEQUALS

The task: near or far

Drive 20 cm. Then, with two separate ifs: if the wall is less than 40 cm away, print near and make the LED red; if it is 40 or more, print far and make it green. The wall has been placed so the answer should be near, but write both.

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

forward(50, distance=20)
d = distance()
if d < 40:
    print("near")

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

QR code
Do it on the robot
www.bugbotlab.com/learn/f2-2-selection-if/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Print "even" if the battery percentage is an even number (remember % from lesson F1.9).
  2. Drive 10 cm only if the way ahead is clear for at least 30 cm, and print what you decided.
  3. Ask for a password with input and turn the LED green only if it is right.