Challenge - 5 Problems
Elif Ladder Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of elif ladder with multiple conditions
What is the output of this Python code?
Python
x = 15 if x < 10: print("Less than 10") elif x < 20: print("Between 10 and 19") elif x < 30: print("Between 20 and 29") else: print("30 or more")
Attempts:
2 left
💡 Hint
Check which condition is true first in the elif ladder.
✗ Incorrect
The variable x is 15. The first if condition (x < 10) is false. The first elif (x < 20) is true, so it prints 'Between 10 and 19' and skips the rest.
❓ Predict Output
intermediate2:00remaining
Elif ladder with overlapping conditions
What will this code print?
Python
score = 75 if score >= 90: print("Grade A") elif score >= 80: print("Grade B") elif score >= 70: print("Grade C") else: print("Grade F")
Attempts:
2 left
💡 Hint
Check conditions from top to bottom and stop at the first true one.
✗ Incorrect
score is 75. The first two conditions are false. The third condition (score >= 70) is true, so it prints 'Grade C'.
❓ Predict Output
advanced2:00remaining
Elif ladder with nested conditions
What is the output of this code?
Python
num = 0 if num > 0: if num % 2 == 0: print("Positive even") else: print("Positive odd") elif num == 0: print("Zero") else: print("Negative")
Attempts:
2 left
💡 Hint
Check the first condition and then the elif condition.
✗ Incorrect
num is 0. The first if (num > 0) is false, so it checks elif (num == 0) which is true, so it prints 'Zero'.
❓ Predict Output
advanced2:00remaining
Elif ladder with boolean expressions
What will this code print?
Python
a = True b = False if a and b: print("Both True") elif a or b: print("One True") else: print("None True")
Attempts:
2 left
💡 Hint
Evaluate the boolean expressions carefully.
✗ Incorrect
a is True and b is False. The first condition (a and b) is False. The second condition (a or b) is True, so it prints 'One True'.
❓ Predict Output
expert2:00remaining
Elif ladder with variable reassignment inside conditions
What is the output of this code?
Python
x = 5 if x > 10: x = x + 10 print(x) elif x > 3: x = x * 2 print(x) else: x = x - 1 print(x) print(x)
Attempts:
2 left
💡 Hint
Check how x changes inside the elif block and then the final print.
✗ Incorrect
x is 5. The first if (x > 10) is false. The elif (x > 3) is true, so x becomes 5*2=10 and prints 10. Then the last print prints the updated x which is 10.