Quiz: If, Elif, Else

Check your understanding of Python if, elif, else, logical operators, shorthand conditions, and nested ifs with this interactive MCQ quiz.

1.

What will the following code output?

python
1
2
3
4
a = 5  
b = 10  
if b > a:  
    print("b is greater than a")
2.

What will cause an IndentationError in Python?

3.

What is the output of this code?

python
1
2
3
4
5
6
7
8
a = 10  
b = 10  
if b > a:  
    print("b is greater")  
elif a == b:  
    print("Equal")
else:  
    print("a is greater")
4.

What will this logical operator expression return?

python
1
2
3
4
5
a = 20  
b = 10  
c = 30  
if a > b and c > a:  
    print("Both conditions are True")