0
0
Pythonprogramming~20 mins

If–else execution flow in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
If–else 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 > 15:
        print("A")
    else:
        print("B")
else:
    print("C")
AB
BC
CA
DNo output
Attempts:
2 left
💡 Hint
Check the conditions step by step, starting from the outer if.
Predict Output
intermediate
2:00remaining
If–else with multiple conditions
What will be printed by this code?
Python
score = 75
if score >= 90:
    print("Excellent")
elif score >= 70:
    print("Good")
else:
    print("Try again")
AExcellent
BNo output
CTry again
DGood
Attempts:
2 left
💡 Hint
Check which condition matches the score first.
Predict Output
advanced
2:00remaining
If–else with assignment expressions
What is the output of this code using the walrus operator?
Python
if (n := 4) > 3:
    print(f"Number {n} is greater than 3")
else:
    print(f"Number {n} is not greater than 3")
ANumber 4 is greater than 3
BNumber 4 is not greater than 3
CNo output
DSyntaxError
Attempts:
2 left
💡 Hint
The walrus operator assigns and returns the value in the condition.
Predict Output
advanced
2:00remaining
If–else with match-case and else
What will this code print?
Python
value = 2
match value:
    case 1:
        print("One")
    case 2:
        print("Two")
    case _:
        print("Other")
AOne
BTwo
COther
DSyntaxError
Attempts:
2 left
💡 Hint
The match-case checks the value against each case.
Predict Output
expert
2:00remaining
Complex if–else with multiple conditions and logical operators
What is the output of this code?
Python
a = 5
b = 10
if a > 0 and b < 5:
    print("X")
elif a > 0 or b < 5:
    print("Y")
else:
    print("Z")
AZ
BX
CY
DNo output
Attempts:
2 left
💡 Hint
Evaluate each condition carefully with the values of a and b.