PYTHON BASICSChapter 2 · Conditionals and logic
Branching paths
An if statement runs a block of code only if a condition is True. An optional else block runs instead if the condition is False. Indent the code inside each block using spaces.
Worked example
How it reads
- if sky == "clear": checks if the variable matches "clear"
- The indented lines run only if their corresponding condition is met
- else: captures any case where the condition was False

Cloud tip: Python uses indentation (4 spaces) to group blocks of code. Always make sure your indentation matches.


