Answer key · 12 questions

Python If, Elif, and Else Exercises With Answers

All 12 questions for Python If, Elif, and Else in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

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.

01 · Multiple choice

Which operator checks whether two values are equal?

  1. !=
  2. =
  3. ==correct
  4. =>

Answer: ==

Why: == compares values; = assigns a value.

02 · Multiple choice

What is printed when score is 85?

score = 85
if score >= 90:
    print("A")
elif score >= 80:
    print("B")
else:
    print("C")
  1. C
  2. Nothing
  3. Bcorrect
  4. A

Answer: B

Why: 85 is not at least 90, but it is at least 80, so the elif branch runs.

03 · Multiple choice

When is A and B true?

  1. When at least one is true
  2. Only when both are false
  3. When exactly one is false
  4. Only when both are truecorrect

Answer: Only when both are true

Why: and requires both operands to be truthy.

04 · Multiple choice

What does the program output?

x = 10
if x > 5:
    print("big")
else:
    print("small")
  1. small
  2. Nothing
  3. bigcorrect
  4. True

Answer: big

Why: 10 is greater than 5, so the if branch runs.

05 · Fill in the blank

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.

06 · Fill in the blank

Complete the keyword that starts the first branch.

____ score >= 90:
    print("A")

Answer: if

Why: Every conditional chain starts with if.

07 · Fill in the blank

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.

08 · Fill in the blank

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.

09 · Predict output

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.

10 · Predict output

What is printed?

x = 3
print("yes" if x > 0 else "no")

Answer: yes

Why: The condition is true, so the expression returns yes.

11 · Predict output

What is the output?

age = 20
member = True
print(age >= 18 and member)

Answer: True

Why: Both sides are true, so and returns True.

12 · Predict output

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.

Practice this lesson