Challenge - 5 Problems
If–else Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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")
Attempts:
2 left
💡 Hint
Check the conditions step by step, starting from the outer if.
✗ Incorrect
The variable x is 10, which is greater than 5, so the outer if is true.
Then the inner if checks if x is greater than 15, which is false.
So the else of the inner block runs, printing "B".
❓ Predict Output
intermediate2: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")
Attempts:
2 left
💡 Hint
Check which condition matches the score first.
✗ Incorrect
The score is 75.
The first condition score >= 90 is false.
The second condition score >= 70 is true, so it prints "Good".
❓ Predict Output
advanced2: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")
Attempts:
2 left
💡 Hint
The walrus operator assigns and returns the value in the condition.
✗ Incorrect
The walrus operator n := 4 assigns 4 to n and returns 4.
Since 4 > 3 is true, it prints "Number 4 is greater than 3".
❓ Predict Output
advanced2: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")
Attempts:
2 left
💡 Hint
The match-case checks the value against each case.
✗ Incorrect
The variable value is 2.
The case 2 matches, so it prints "Two".
❓ Predict Output
expert2: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")
Attempts:
2 left
💡 Hint
Evaluate each condition carefully with the values of a and b.
✗ Incorrect
a is 5 (greater than 0), b is 10 (not less than 5).
The first condition a > 0 and b < 5 is false because b < 5 is false.
The second condition a > 0 or b < 5 is true because a > 0 is true.
So it prints "Y".