Learn Without Walls
← Back to Module 4

Module 4 Quiz: Conditionals

12 questions • Test your understanding

Question 1: What does the == operator do?

  • Assigns a value to a variable
  • Checks if two values are equal
  • Checks if two values are not equal
  • Creates a copy of a value
Correct! The == operator compares two values and returns True if they are equal. The single = is for assignment.

Question 2: What will this code print?

x = 10
if x > 5:
    print("A")
elif x > 8:
    print("B")
else:
    print("C")
  • A and B
  • B
  • A
  • C
Correct! Python checks conditions top to bottom. 10 > 5 is True, so it prints "A" and skips the rest of the elif/else chain.

Question 3: What is the result of: "apple" == "Apple"?

  • False
  • True
  • Error
  • None
Correct! String comparison is case-sensitive. "apple" and "Apple" differ in the first character (lowercase vs uppercase), so the result is False.

Question 4: What does this expression evaluate to: True and False?

  • True
  • Error
  • None
  • False
Correct! The and operator returns True only when both operands are True. Since one is False, the result is False.

Question 5: What does this expression evaluate to: False or True?

  • False
  • True
  • None
  • Error
Correct! The or operator returns True when at least one operand is True.

Question 6: What is missing from this code?

if score >= 90
    print("A")
  • Parentheses around the condition
  • The else clause
  • A colon after the condition
  • An indented block
Correct! The if statement requires a colon : at the end of the condition line. It should be if score >= 90:

Question 7: What will this code print?

x = 5
if x > 3:
    print("A")
if x > 4:
    print("B")
if x > 5:
    print("C")
  • A and B
  • A only
  • A, B, and C
  • B only
Correct! These are three separate if statements (not if-elif), so each is checked independently. 5 > 3 is True (print A), 5 > 4 is True (print B), 5 > 5 is False (skip C).

Question 8: What does not (5 > 3) evaluate to?

  • True
  • False
  • Error
  • 5
Correct! 5 > 3 is True, and not True is False.

Question 9: What will this code print?

age = 20
has_id = False

if age >= 18 and has_id:
    print("Entry allowed")
else:
    print("Entry denied")
  • Entry allowed
  • Nothing
  • Entry denied
  • Error
Correct! Although age >= 18 is True, has_id is False. Since and requires both to be True, the condition is False, so "Entry denied" prints.

Question 10: Which operator has the highest precedence?

  • and
  • or
  • == (comparison)
  • not
Correct! Among logical operators, not has the highest precedence, followed by and, then or.

Question 11: What is the result of: "5" == 5?

  • False
  • True
  • Error
  • "5"
Correct! "5" is a string and 5 is an integer. They are different types, so == returns False.

Question 12: What will this nested conditional print?

x = 15
y = 5

if x > 10:
    if y > 10:
        print("Both big")
    else:
        print("x big, y small")
else:
    print("x small")
  • Both big
  • x big, y small
  • x small
  • Nothing
Correct! x > 10 is True (15 > 10), so we enter the outer if. Then y > 10 is False (5 is not > 10), so the inner else runs, printing "x big, y small".

Quiz Results

Back to Module 4