Skip to main content

Section 3.4 Evaluate Conditionals-WE2-P1

Subgoals for Evaluating Selection Statements.

  1. Diagram which statements go together by indentation
  2. For conditional, determine whether expression is true
    1. If true, follow true branch
    1. If false, follow next elif/else branch or exit conditional if no else branch
  3. 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.
Q11: What is the output of the following code?
a = 10
b = 5
c = 3
if b < c:
    print(c)
elif b < a:
    print(a)
else:
    print(b)
You have attempted of activities on this page.