Scratch repeat block as a for loop

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Scratch repeat block as a for loop

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which Python code does the same job as the Scratch block 'repeat 10'?
A for i in range(10):
B repeat 10:
2. In a Scratch 'repeat 10' block, the blocks inside the C-shape are the ones that repeat. How does Python show which lines are inside the loop?
A They are indented underneath the for line
B They are wrapped in curly brackets { }
3. Which for loop line has the correct syntax?
A for i in range(10)
B for i in range(10):
4. What values does i take in for i in range(10):?
A 1, 2, 3, ... 10
B 0, 1, 2, ... 9
5. How many times does this code print Hi? for i in range(10): print('Hi')
A 10 times
B 9 times

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1for i in range(10): APython's version of the Scratch repeat 10 block: it repeats the indented lines 10 times
2for i in range(5): print(i) BThe print line is not indented, so Python does not know it is inside the loop. It should be indented 4 spaces.
3A Scratch repeat 4 block with a move block inside it becomes a for loop with the move line indented underneath Cfor i in range(4): print("move")
4A Scratch repeat 3 block with two blocks inside it becomes a for loop with both lines indented the same amount DThe colon is missing at the end of the for line, so Python gives a syntax error. It should be for i in range(10):
5for i in range(10) print("Hi") EPrints 0, 1, 2, 3, 4 because the counter i starts at 0 and the loop runs 5 times
6for i in range(10): print("Hi") Ffor i in range(3): print("jump") print("spin")

Definitions

for i in range(10):

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
for i in _____(10): print("Jump")
2.
# Scratch: repeat 10 for i in range(__): print("Clap")
3.
___ i in range(5): print("Step")
4.
for i in range(3): print(_)
5.
for i in range(3): print(i + _)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A print("Start")
B for i in range(10):
C print("Step)
Question 2
A count = 0
B for i in range(10)
C count = count + 1
Question 3
A for i in range[10]:
B print("Jump")
C print("Done")
Question 4
A print("Dance time")
B For i in range(10):
C print("Spin")
Question 5
A for i in range(10):
B print("Move")
C print("Turn")
D Print("Finished")

Answer Key

Scratch repeat block as a for loop
Section A: Quick Questions
Q1
A — for i in range(10):
Q2
A — They are indented underneath the for line
Q3
B — for i in range(10):
Q4
B — 0, 1, 2, ... 9
Q5
A — 10 times
Section B: Match the Pairs
Q1
for i in range(10): → Python's version of the Scratch repeat 10 block: it repeats the indented lines 10 times
Q2
for i in range(5): print(i) → Prints 0, 1, 2, 3, 4 because the counter i starts at 0 and the loop runs 5 times
Q3
A Scratch repeat 4 block with a move block inside it becomes a for loop with the move line indented underneath → for i in range(4): print("move")
Q4
A Scratch repeat 3 block with two blocks inside it becomes a for loop with both lines indented the same amount → for i in range(3): print("jump") print("spin")
Q5
for i in range(10) print("Hi") → The colon is missing at the end of the for line, so Python gives a syntax error. It should be for i in range(10):
Q6
for i in range(10): print("Hi") → The print line is not indented, so Python does not know it is inside the loop. It should be indented 4 spaces.
Section C: Definitions
Q1
for i in range(10): — Python's version of the Scratch repeat 10 block. The lines indented under it run 10 times, and i counts from 0 to 9.
Section D: Fill in the Blanks
Q1
for i in range(10): print("Jump")
Q2
# Scratch: repeat 10 for i in range(10): print("Clap")
Q3
for i in range(5): print("Step")
Q4
for i in range(3): print(i)
Q5
for i in range(3): print(i + 1)
Section E: Spot the Error
Q1
C — The string is missing its closing quote. The line inside the loop should be ' print("Step")'.
Q2
B — The for line must end with a colon. It should be 'for i in range(10):'.
Q3
A — range uses round brackets, not square brackets. It should be 'for i in range(10):'.
Q4
B — Python is case sensitive, so 'for' must be lowercase. It should be 'for i in range(10):'.
Q5
D — print must be written in lowercase. 'Print' causes a NameError. It should be 'print("Finished")'.