Module 4 Quiz: Conditionals
12 questions • Test your understanding
Question 1: What does the == operator do?
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")
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"?
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?
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?
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")
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")
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?
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")
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?
Correct! Among logical operators,
not has the highest precedence, followed by and, then or.Question 11: What is the result of: "5" == 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")
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".