Challenge - 5 Problems
Nested Conditional Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested if-else with numbers
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 first condition, then the nested one inside it.
✗ Incorrect
x is 10, which is greater than 5 and less than 15, so the inner if prints 'A'.
❓ Predict Output
intermediate2:00remaining
Nested if-else with strings
What will this code print?
Python
word = "hello" if len(word) > 3: if word[0] == 'h': print("Starts with h") else: print("Long word") else: print("Short word")
Attempts:
2 left
💡 Hint
Check the length and first letter of the word.
✗ Incorrect
The word 'hello' has length 5 (>3) and starts with 'h', so it prints 'Starts with h'.
❓ Predict Output
advanced2:00remaining
Nested if-else with multiple conditions
What is the output of this code?
Python
num = 7 if num % 2 == 0: if num > 10: print("Even and large") else: print("Even and small") else: if num > 5: print("Odd and large") else: print("Odd and small")
Attempts:
2 left
💡 Hint
Check if the number is even or odd, then check its size.
✗ Incorrect
7 is odd (not divisible by 2) and greater than 5, so it prints 'Odd and large'.
❓ Predict Output
advanced2:00remaining
Nested if-else with boolean logic
What will this code print?
Python
flag1 = True flag2 = False if flag1: if flag2: print("Both True") else: print("Only flag1 True") else: print("flag1 is False")
Attempts:
2 left
💡 Hint
Check the values of flag1 and flag2 carefully.
✗ Incorrect
flag1 is True but flag2 is False, so it prints 'Only flag1 True'.
❓ Predict Output
expert2:00remaining
Nested if-else with variable reassignment
What is the value of variable result after running this code?
Python
x = 3 if x > 0: if x % 2 == 0: result = "Positive even" else: result = "Positive odd" else: if x == 0: result = "Zero" else: result = "Negative"
Attempts:
2 left
💡 Hint
Check if x is positive and then if it is even or odd.
✗ Incorrect
x is 3, which is positive and odd, so result is 'Positive odd'.