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

Python If–Else MCQs (25)

Each question focuses on if, elif, else, and truthiness. Answers at the end

1) What is the output?

x = 5
if x > 3:
    print("A")
else:
    print("B")
A. A
B. B
C. Error
D. No output

2) What prints?

x = 0
if x:
    print("True")
else:
    print("False")
A. True
B. False
C. 0
D. Error

3) Choose the output.

x = ""
if x == "":
    print("Empty")
elif x:
    print("Non-empty")
else:
    print("Else")
A. Empty
B. Non-empty
C. Else
D. Error

4) Output?

x = 7
if x % 2 == 0:
    print("Even")
else:
    print("Odd")
A. Even
B. Odd
C. 7
D. Error

5) What prints?

x = None
if x is None:
    print("N")
else:
    print("X")
A. N
B. X
C. None
D. Error

6) Output?

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

7) What is printed?

x = 3
if x > 2:
    print("Yes")
    print("Done")
A. Yes
B. Done
C. Yes \n Done
D. No output

8) Choose the output.

x = []
if x:
    print("List True")
else:
    print("List False")
A. List True
B. List False
C. []
D. Error

9) Output?

x = -1
if x:
    print("Non-zero")
else:
    print("Zero")
A. Non-zero
B. Zero
C. -1
D. Error

10) What prints?

x = 5
y = 10
if x and y > 5:
    print("OK")
else:
    print("NO")
Note: and precedence.
A. OK
B. NO
C. Error
D. None

11) Output?

n = 0
if n == 0:
    pass
else:
    print("X")
print("Y")
A. X
B. Y
C. X then Y
D. No output

12) What is printed?

val = "0"
if val:
    print("T")
else:
    print("F")
A. T
B. F
C. 0
D. Error

13) Output?

a = 3
b = 3
if a == b:
    print("Equal")
elif a > b:
    print("A")
else:
    print("B")
A. Equal
B. A
C. B
D. Error

14) Choose the output.

x = [1, 2]
if len(x) == 2:
    print("Two")
elif len(x) == 1:
    print("One")
else:
    print("Other")
A. Two
B. One
C. Other
D. Error

15) Output?

flag = False
if not flag:
    print("Go")
else:
    print("Stop")
A. Go
B. Stop
C. False
D. Error

16) What prints?

d = {}
if "a" in d:
    print("Yes")
else:
    print("No")
A. Yes
B. No
C. {}
D. Error

17) Output?

n = 5
if n % 5 == 0 and n % 2 == 0:
    print("A")
elif n % 5 == 0:
    print("B")
else:
    print("C")
A. A
B. B
C. C
D. Error

18) Choose the output.

x = [0]
if x and x[0]:
    print("T")
else:
    print("F")
A. T
B. F
C. 0
D. Error

19) Output?

s = "python"
if "py" in s:
    print("Yes")
else:
    print("No")
A. Yes
B. No
C. python
D. Error

20) What prints?

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

21) Output?

n = -5
if n > 0:
    print("P")
elif n == 0:
    print("Z")
else:
    print("N")
A. P
B. Z
C. N
D. Error

22) Choose the output.

x = " "
if x.strip():
    print("X")
else:
    print("Y")
A. X
B. Y
C. (space)
D. Error

23) Output?

a = 1
b = 2
if (a > b) or (b > a and a == 1):
    print("T")
else:
    print("F")
A. T
B. F
C. 1
D. 2

24) What prints?

x = [1, 2, 3]
if x.pop() and x:
    print(len(x))
else:
    print(0)
Note: list.pop() returns the removed element.
A. 3
B. 2
C. 0
D. Error

25) Output?

val = {"a": 1}
if val.get("b", 0):
    print("Has b")
else:
    print("No b")
A. Has b
B. No b
C. 0
D. Error

Answer Key

1) A

2) B

3) A

4) B

5) A

6) B

7) C

8) B

9) A

10) A

11) B

12) A

13) A

14) A

15) A

16) B

17) B

18) B

19) A

20) B

21) C

22) B

23) A

24) B

25) B