Decisions and loops · GCSE · OCR J277 2.2.1, AQA 8525 3.2.2, Edexcel 1CP2 6.2.2 · about 15 min
range, the loop variable, and repeating a known number of times.
[1 mark]What does this program print?
for i in range(4):
print(i)[1 mark]What does this program print?
for n in range(1, 4):
print(n, n * n)[1 mark]What does this print? total = 0 then for i in range(5): total = total + i, then print(total)
[1 mark]A square has four sides. Which loop drives it?
for i in range(4): with forward and turn_right(30, angle=90) insidefor i in range(3): with forward and turn_right(30, angle=90) insidefor i in range(90): with forward insidefor i in 4: with forward and turn_right(30, angle=90) inside[1 mark]How many times does the block under for i in range(10): run?
[1 mark]Put the lines in order to print corner 1, corner 2, corner 3.
Number the lines 1 to 3 to put them in the right order.
for i in range(3): print("corner", corner) corner = i + 1[1 mark]What does this program print?
for n in range(0, 20, 5):
print(n)[1 mark]In OCR's Reference Language, for i = 1 to 5 ... next i. How many times does the loop run?
[1 mark]What does AQA call a count-controlled loop?
Drive a square of 30 cm sides with a for loop, printing corner 1, corner 2, corner 3, corner 4 as you go, and finish facing the way you started.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
for i in range(4):
forward(60, distance=30)Plan your program here, then type it in and press Run.
for loop (three sides, turn_right(30, angle=120)).wait(0.2) inside a loop.