The function generates a sequence of integers for a for loop.
What does the loop variable do in a for loop?
What is the default step in range() when you omit it?
Fill in the Blanks
Click on words from the word bank below to fill in the blanks in the paragraph.
Combining these ideas, definite iteration with for and range is the standard approach to repeat a known number of times. Remember that start defaults to 0, stop is exclusive, and step defaults to 1. Use the loop variable inside the loop body, and always watch for off-by-one ____ to ensure correct ____. For example, summing numbers 1 to 5 uses range(1, 6) in a for loop.
Word Bank (Click words to fill in blanks):
outputmistakes
What is an off-by-one error in a for loop?
Python implements definite iteration with a loop.
Which keyword starts a for loop in Python?
Spot the Lie...
Three statements are shown below. Two are true and one is a lie. Click on the statement that is the lie.
Fill in the Blanks
Click on words from the word bank below to fill in the blanks in the paragraph.
A ____ loop walks through each value in a ____. With ____(1, 5) the values are 1, 2, 3 and 4 because stop is ____.
Word Bank (Click words to fill in blanks):
rangeforexclusivesequence
How many times does this loop run?
for i in range(0, 10, 2): print(i)
What is definite iteration used for?
Spot the Lie...
Three statements are shown below. Two are true and one is a lie. Click on the statement that is the lie.
The name that takes each value from the sequence is called the .
Fill in the Blanks
Click on words from the word bank below to fill in the blanks in the paragraph.
Definite iteration in Python repeats a block of code a ____ number of times, useful when the number of passes is ____ beforehand. This is commonly implemented using a ____ loop that iterates over a ____ generated by the range function. For example, range(5) produces integers from 0 up to but not including 5, resulting in loop variable values 0, 1, 2, 3, and 4.
Word Bank (Click words to fill in blanks):
sequenceforknownfixed
Fill in the Blanks
Click on words from the word bank below to fill in the blanks in the paragraph.
For loops in Python can iterate directly through the elements of a ____, without using range or manual ____. Each pass of the loop assigns the loop variable to the next item in the list, which can make code clearer and easier to ____ especially for beginners. For example, iterating over names = ["Sam", "Alex", "Jo"] prints each name in turn.
Word Bank (Click words to fill in blanks):
listreadindexing
If start is omitted from range(5), what happens?
Fill in the Blanks
Click on words from the word bank below to fill in the blanks in the paragraph.
The range function can take up to three arguments: ____, ____, and ____. The start argument defaults to 0 if omitted, the stop argument is always ____, and the step argument defaults to 1 if not specified. A negative step can be used to count ____, allowing flexible control over the iteration sequence.
Word Bank (Click words to fill in blanks):
stepbackwardsstopstartexclusive
What does this code print?
for i in range(3): print(i)
In range(start, stop, step), the value is exclusive and is never included.
What does range(1, 8, 2) produce?
Why does for i in range(1, 5) print 1 2 3 4 and not 5?