# If-Else Statement MCQ in Python

Q1) Can we write if/else into one line in python?

a) Yes
b) No
c) if/else not used in python
d) None of the above

Ans:- a) Yes

Explanation: We can write if/else in one line. For eg i = 2 if a > 5 else 0.

Q2) Which one of the following is a valid Python if statement.

a) if a>=2 :
b) if (a >= 2)
c) if (a => 22)
d) if a >= 22

Ans:- a) if a>=2 :
Explanation: If statement always ended with colon (:).

Q3) What keyword would you use to add an alternative condition to an if statement?

a) else if
b) elseif
c) elif
d) None of the above

Ans:- c) elif

Q4) What is the output of the given below program?

``````if 1 + 3 == 7:
print("Hello")
else:
print("Know Program")
``````

a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error

Ans:- b) Know Program

The 1+3 = 4 which is not equal to 7 therefore else block will be executed.

Q5) What is the output of the given below program?

``````if 3 + 4 == 7:
print("Hi")
else:
print("Know Program")
print("Hello")
``````

a) Hi
b) Know Program

c)
Hi
Hello

d)
Know Program
Hello

Ans:- c)
Hi
Hello

The 3+4 = 7 is equal to 7 therefore if block will be executed. The remaining statement after if-else block also will be executed.

Q6) Find the output of the given Python program?

``````a = 25
if a < 15:
print("Hi")
if a <= 30:
print("Hello")
else:
print("Know Program")
``````

a) Hi
b) Hello
c) Know Program
d) Compiled Successfully, No Output.

Ans:- b) Hello

Here 25 < 15 => false; therefore the if-block will not be executed. Next, 25 <= 30, condition becomes true therefore if-block will be executed.

Q7) What is the output of the given below program?

``````a = 25
if a > 15:
print("Hi")
if a <= 30:
print("Hello")
else:
print("Know Program")
``````

a) Hi
b) Hello

c)
Hi
Hello

d) Hi
Know Program

e) Hello
Know Program

Ans:- c)
Hi
Hello

Here 25 > 15, condition is true therefore first if-statment will be executed. Next, 25 <= 30, condition is true therefore second if-statement also will be executed.

Q8) Find the output of the given Python program?

``````a, b, c = 1, 3, 5
if a > 0:
if b < 2:
print("Hi")
elif c > 3:
print("Hello")
else:
print("Know Program")
``````

a) Hi
b) Hello
c) Know Program
d) Compiled Successfully, No Output.

Ans:- b) Hello

Q9) Find the output of the given Python program?

``````a, b, c = 1, 3, 5
if a + b + c:
print("Hello")
else:
print("Know Program")
``````

a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error

Ans:- a) Hello

Q10) What is the output of the given below program?

``````if a < b:
print("Hello")
else:
print("Know Program")
``````

a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error

Ans:- d) Error

The variables are not assigned with any value.

Q11) What is the output of the given below program?

``````a = b = true
if (a and b):
print("Hello")
else:
print("Know Program")``````

a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error

Ans:- d) Error

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!