Challenge - 5 Problems
Python Indentation 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 indentation
What is the output of this Python code snippet?
Python
x = 5 if x > 3: if x < 10: print("A") else: print("B") else: print("C")
Attempts:
2 left
💡 Hint
Check which conditions are true and how indentation groups the print statements.
✗ Incorrect
The first if (x > 3) is true, then the nested if (x < 10) is also true, so it prints "A".
❓ Predict Output
intermediate2:00remaining
Effect of wrong indentation on loop execution
What will be printed by this code?
Python
for i in range(3): print(i) print('Done')
Attempts:
2 left
💡 Hint
Look carefully at the indentation of the last print statement.
✗ Incorrect
The last print is indented less than the for loop block but not aligned with it, causing IndentationError.
❓ Predict Output
advanced2:00remaining
Output of function with mixed indentation
What is the output of this code?
Python
def f(): x = 1 if x == 1: print('Yes') print('No') f()
Attempts:
2 left
💡 Hint
Check the indentation of the second print inside the function.
✗ Incorrect
The second print is indented with 5 spaces, which is inconsistent and causes IndentationError.
❓ Predict Output
advanced2:00remaining
Output of code with multiple blocks and else
What will this code print?
Python
for i in range(2): if i == 0: print('Zero') else: print('Not zero') print('Loop done')
Attempts:
2 left
💡 Hint
Notice the indentation of the last print statement inside the loop.
✗ Incorrect
The last print is inside the loop but outside the if-else, so it runs every iteration after the if-else.
🧠 Conceptual
expert3:00remaining
Identifying the cause of unexpected output due to indentation
Consider this code:
x = 10
if x > 5:
print('Big')
if x > 8:
print('Very big')
else:
print('Small')
Why does it print only "Big" and "Very big" and never "Small"?
Attempts:
2 left
💡 Hint
Check which if the else is paired with based on indentation.
✗ Incorrect
The else is aligned with the first if, so it runs only if x > 5 is false. Since x=10 > 5, else is skipped.