Nested if statements in Python
An if statement indented inside another if block. The inner condition is only checked when the outer condition is True.
Understanding Nested if statements in Python in VCE Software Development U3O1
What it does: The extra indentation on the inner if shows it sits inside the outer if block. It only runs when logged_in is True. temp > 20 is False, so Python skips the whole outer block and never tests temp > 30. Nothing is printed. Two nested ifs with no else can be combined into one if using and. Both conditions must be True for the code to run.
Common mistakes: Python's Boolean value is capitalised: True. Lowercase true is an undefined name, so the outer condition causes a NameError and the nested if never runs. It should be: if logged_in == True:. The keyword is misspelled. The outer statement must start with if, otherwise the nested if inside it has no valid outer block. It should be: if mark >= 50:.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 10–47) and word search (Modules 10–71).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
nested ifFill in the Blanks
Spot the Error
Student with a class code? Join your class →