0
0
Pythonprogramming~20 mins

If statement execution flow in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
If Statement Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of nested if-else blocks
What is the output of this Python code?
Python
x = 10
if x > 5:
    if x > 8:
        print("A")
    else:
        print("B")
else:
    print("C")
AA
BB
CC
DNo output
Attempts:
2 left
💡 Hint
Check the conditions step by step from top to bottom.
Predict Output
intermediate
2:00remaining
If-elif-else execution output
What will be printed when this code runs?
Python
num = 0
if num > 0:
    print("Positive")
elif num == 0:
    print("Zero")
else:
    print("Negative")
AZero
BNo output
CNegative
DPositive
Attempts:
2 left
💡 Hint
Check which condition matches the value of num.
Predict Output
advanced
2:00remaining
Output with multiple if statements
What is the output of this code snippet?
Python
a = 3
if a > 2:
    print("X")
if a > 4:
    print("Y")
else:
    print("Z")
A
X
Y
B
X
Z
CZ
DX
Attempts:
2 left
💡 Hint
Remember that the else belongs to the second if only.
Predict Output
advanced
2:00remaining
If statement with logical operators
What will this code print?
Python
x = 7
y = 5
if x > 5 and y < 10:
    print("Yes")
elif x > 5 or y > 10:
    print("Maybe")
else:
    print("No")
ANo
BMaybe
CYes
DSyntaxError
Attempts:
2 left
💡 Hint
Check the first condition carefully with both parts.
Predict Output
expert
2:00remaining
If statement with assignment expression
What is the output of this code?
Python
if (n := 4) > 3:
    print(n * 2)
else:
    print(n / 2)
A4
B2.0
CSyntaxError
D8
Attempts:
2 left
💡 Hint
The walrus operator assigns and returns the value in the condition.