Skip to main content\(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\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.4 Evaluate Conditionals-WE2-P1
Subgoals for Evaluating Selection Statements.
Diagram which statements go together by indentation
-
For conditional, determine whether expression is true
If true, follow true branch
If false, follow next elif/else branch or exit conditional if no else branch
Repeat step 2 as necessary
Subsection 3.4.1 Conditionals-WE2-P1
Each question below is independent.
Exercises Exercises
1.
Q7: What is the output of the following code?
x = 0
if x = 0: # look closely!
print("0 is true")
else:
print("0 is false")
0 is true
0 is false
There is no output because a compiler error occurs
There is no output because an exception occurs
2.
Q8: What is the output of the following code?
if False:
print("it is true")
else:
print("it is false")
it is true
it is false
There is no output because a compiler error occurs
There is no output because an exception occurs
3.
Q9: What is the output of the following code?
if 12 < 12:
print("Never")
else:
print("Always")
Never
Always
There is no output because a compiler error occurs
There is no output because an exception occurs
4.
Q10: What is the output of the following code?
var1 = 15.0
var2 = 25.12
if 2 * var1 >= var2:
print("O.K.")
else:
print("Not O.K.")
O.K.
Not O.K.
There is no output because a compiler error occurs
There is no output because an exception occurs
5.
You have attempted
of
activities on this page.