Decisions and loops · GCSE · OCR J277 2.2.1, AQA 8525 3.2.5, Edexcel 1CP2 1.2.3 · about 15 min
Choosing between outcomes, and joining conditions with and, or and not.
[1 mark]What does this program print?
d = 30
if d < 20:
print("stop")
elif d < 40:
print("careful")
else:
print("go")[1 mark]With an if and an else, how many of the two blocks run?
[1 mark]What does this program print?
print(True and False) print(True or False) print(not True)
[1 mark]The traffic light checks d < 40 first and d < 20 second, with elif. What goes wrong when d is 10?
[1 mark]What does this program print?
d = 50
b = 10
if d > 30 and b > 20:
print("drive")
else:
print("stay")[1 mark]What is elif short for? (two words)
[1 mark]In a truth table, when is A OR B False?
[1 mark]What does this program print?
d = 25
if d >= 20 and d <= 40:
print("in the zone")
else:
print("outside")Drive 15 cm, then read the distance and set the LED: red and print stop if the wall is under 20 cm away; orange and careful if under 40; green and go otherwise. The wall is placed so that the right answer is orange, but write all three branches.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
forward(50, distance=15)
d = distance()
if d < 20:
led("red")
print("stop")Plan your program here, then type it in and press Run.
and.blocked case comes first, using not.