This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python If, Elif, and Else, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
Which operator checks whether two values are equal?
Answer: ==
Why: == compares values; = assigns a value.
What is printed when score is 85?
score = 85
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("C")Answer: B
Why: 85 is not at least 90, but it is at least 80, so the elif branch runs.
When is A and B true?
Answer: Only when both are true
Why: and requires both operands to be truthy.
What does the program output?
x = 10
if x > 5:
print("big")
else:
print("small")Answer: big
Why: 10 is greater than 5, so the if branch runs.
Complete the comparison so the message prints when total is at least 100.
if total ____ 100:
print("Free shipping")Answer: >=
Why: The >= operator means greater than or equal to.
Complete the keyword that starts the first branch.
____ score >= 90:
print("A")Answer: if
Why: Every conditional chain starts with if.
Complete the boolean operator so both conditions must be true.
if age >= 18 ____ has_id:
print("Allowed")Answer: and
Why: and returns true only when both sides are true.
Complete the keyword that handles every remaining case.
if total >= 50:
print("Free")
____:
print("Fee")Answer: else
Why: else runs when none of the earlier conditions matched.
What appears on the screen?
score = 85
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("C")Answer: B
Why: The elif branch matches 85.
What is printed?
x = 3
print("yes" if x > 0 else "no")Answer: yes
Why: The condition is true, so the expression returns yes.
What is the output?
age = 20
member = True
print(age >= 18 and member)Answer: True
Why: Both sides are true, so and returns True.
What does this code print?
print(not False)Answer: True
Why: not flips False to True.
Try the questions first
Open the practice page for Python If, Elif, and Else and answer the same 12 questions with instant feedback.