Softenant
Technologies
Python Else–If (elif) Ladder MCQs (25) — Answers at the End

Python Else–If (elif) Ladder MCQs (25)

Covers evaluation order, overlapping conditions, ranges, truthiness, membership, and typical pitfalls. Answers at the end

Python Training in Vizag (Softenant)

1) Output?

x = 7
if x < 5:
    print("A")
elif x < 10:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

2) What prints?

x = 5
if x < 5:
    print(0)
elif x <= 5:
    print(1)
else:
    print(2)
A. 1
B. 0
C. 2
D. Error

3) Choose the output.

x = 9
if x > 0:
    print("P")
elif x > 5:
    print("Q")
else:
    print("R")
A. P
B. Q
C. R
D. No output

4) First match wins?

x = 10
if x > 10:
    print("A")
elif x == 10:
    print("B")
elif x >= 10:
    print("C")
else:
    print("D")
A. A
B. B
C. C
D. D

5) Else case?

x = -1
if x >= 0:
    print("A")
elif x > 10:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

6) Ranges with elif?

score = 85
if score >= 90:
    print("A")
elif 80 <= score < 90:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. Error

7) Truthiness in ladder?

s = ""
if s:
    print("X")
elif s == "":
    print("Y")
else:
    print("Z")
A. X
B. Y
C. Z
D. Error

8) Overlap ordering matters.

n = 100
if n % 2 == 0 and n % 5 == 0:
    print("E")
elif n % 10 == 0:
    print("T")
else:
    print("N")
A. E
B. T
C. N
D. No output

9) First satisfied branch executes.

x = 50
if x >= 50:
    print("A")
elif x >= 60:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

10) Mutually exclusive paths.

x = 0
if x > 0:
    print("P")
elif x < 0:
    print("N")
else:
    print("Z")
A. P
B. N
C. Z
D. No output

11) Compare with nested if (only one branch runs).

x = 3
if x > 0:
    print("P")
elif x > 2:
    print("Q")
else:
    print("R")
A. P
B. Q
C. R
D. PQ

12) First true stops evaluation.

a = 0
if a == 1:
    print("A")
elif a == 0:
    print("B")
elif not a:
    print("C")
else:
    print("D")
A. A
B. B
C. C
D. D

13) Membership in conditions.

name = "anil"
if "a" in name and name.startswith("a"):
    print("X")
elif name.endswith("l"):
    print("Y")
else:
    print("Z")
A. X
B. Y
C. Z
D. No output

14) No else → possible no output.

x = -5
if x > 10:
    print("A")
elif x > 0:
    print("B")
A. A
B. B
C. No output
D. Error

15) Identity vs equality in ladder.

val = 0
if val:
    print(1)
elif val is False:
    print(2)
elif val == 0:
    print(3)
else:
    print(4)
A. 1
B. 2
C. 3
D. 4

16) Combined conditions.

x, y = 3, 4
if x < 2 or y < 3:
    print("A")
elif x <= 3 and y >= 4:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

17) Chained comparisons.

n = 5
if 0 < n < 5:
    print("L")
elif 5 <= n < 10:
    print("M")
else:
    print("N")
A. L
B. M
C. N
D. LM

18) Falsy list.

lst = []
if len(lst):
    print("A")
elif not lst:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

19) None checks in ladder.

msg = None
if msg:
    print("A")
elif msg is None:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

20) No else and no match.

x = 1
if x < 0:
    print("A")
elif x > 2:
    print("B")
A. A
B. B
C. No output
D. Error

21) Computed conditions.

x = 2
if x * 2 == 5:
    print("A")
elif x ** 3 == 8:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

22) Case-handling logic.

s = "abc"
if s == "ABC":
    print("U")
elif s.lower() == "abc":
    print("L")
else:
    print("N")
A. U
B. L
C. N
D. UL

23) Floating-point caution.

x = 0.1 + 0.2
if x == 0.3:
    print("A")
elif abs(x - 0.3) < 1e-9:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

24) Multiple truths — first one only.

flags = (True, True)
if flags[0] and flags[1]:
    print("X")
elif flags[0]:
    print("Y")
elif flags[1]:
    print("Z")
else:
    print("N")
A. X
B. Y
C. Z
D. N

25) Dict membership flow.

d = {}
if "a" in d:
    print("A")
elif not d:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. No output

Answer Key

1) B

2) A

3) A

4) B

5) C

6) B

7) B

8) A

9) A

10) C

11) A

12) B

13) A

14) C

15) C

16) B

17) B

18) B

19) B

20) C

21) B

22) B

23) B

24) A

25) B