Skip to main content
Contents
Search Book
Search Results:
No results.
Readability settings Prev Up Next Scratch ActiveCode Profile
title here
\(
\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 3.2 WriteLoops-Exercise
Subgoals for Writing a Loop.
Determine purpose of loop
Pick a loop structure (while, for, do_while)
Define and initialize variables
Determine termination condition
Invert termination condition to continuation condition
Update Loop Control Variable to reach termination
Exercises Exercises
1.
Put the following code blocks in the correct order to create a program that will print the prime numbers between 1 and 100 (inclusive).
for i in range( 2, 101):Â
---
is_prime = True
---
for j in range( 2, i):
---
if i % j == 0:
---
is_prime = False
---
if is_prime:
---
print(i, end=" ")
You have attempted
of
activities on this page.