Skip to content
dreamcode
dreamcode
Map
Nested checks
Lesson 12 of 77
+15 XP on finish
PYTHON BASICSChapter 2 · Conditionals and logic

Indented checks

You can place if statements inside other if statements. This is called nesting. The inner check only runs if the outer check succeeds. You can also nest conditionals inside loops.

Worked example

How it reads

  • if sky == "cloudy": checks the outer condition
  • if rain: checks the inner condition only when the outer is True
Cloud tip: Every level of nesting adds another 4 spaces of indentation. Keep nesting shallow so your code stays readable.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Give the inner check an else that prints Fourth quadrant, then set y = -3 to reach it.

Press Run to check your work.