Skip to main content\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 16.16 Review - The range() Function
Practice understanding how
range() works in for loops, including the start, stop, and step values.
Subsection 16.16.1 Part A: Recognize
Checkpoint 16.16.1.
In your own words, explain what each part of range(start, stop, step) means.
-
start: ____________________
-
stop: ____________________
-
end: ____________________
-
Does range(5) include 5? __________
-
What number does range(3, 8) start at? __________
-
What happens in range(10, 0, -1)? __________
Checkpoint 16.16.2.
For each example, list the numbers that would be generated by range().
-
range(5): ____________________
-
range(2,6): ____________________
-
range(1,10,2): ____________________
-
range(10, 4, -2): ____________________
-
range(8, 2): ____________________
Subsection 16.16.2 Part B: Trace
Checkpoint 16.16.3.
Predict what will be printed.
for i in range(5):
print(i)
Checkpoint 16.16.4.
Predict what will be printed.
for i in range(2, 7):
print(i)
Checkpoint 16.16.5.
Predict what will be printed.
for i in range(1, 10, 3):
print(i)
Subsection 16.16.3 Part C: Fix
Checkpoint 16.16.6.
Rewrite the loop so it prints the numbers
0 through
4.
Checkpoint 16.16.7.
Rewrite the loop so it prints the even numbers from
2 to
10.
Checkpoint 16.16.8.
Rewrite the loop so it prints the numbers
5 down to
1.
Subsection 16.16.4 Part D: Create
Checkpoint 16.16.9.
Write a loop for each task:
-
print the numbers 0, 2, 4, 6, 8:
-
print the numbers 10 down to 1
-
print each index and character of the string βhelloβ
You have attempted
of
activities on this page.