Module 6: Simple Decisions - if

Let's explore how programs make choices!

Anatomy of an 'if' Statement

An `if` statement allows code to run *only* if a condition is true. Click the parts below to see what they do.

if temperature > 30: print("It's hot!")

Identify all 5 parts!

Spot the Correct Indentation

Indentation is vital in Python! Click on the code block(s) below where the `print` statement is correctly indented for the `if` statement.

True or False?

The `if` statement depends on whether its condition is True or False. Given the variable value, decide if the condition shown is True or False.

Code Challenge: Simple Check

Time to write your own `if` statement! Use the editor below.

Task: Assume a variable `points = 15`. Write Python code that checks if `points` is greater than 10. If it is, print the message "Level Up!".
Output will appear here...

Computational Thinking Link

How does the `if` statement relate to how we think computationally?

The `if` statement is a fundamental building block in Algorithmic Thinking. It allows us to create different conditional pathways or branches in our instructions. Just like deciding "IF it's raining, THEN take an umbrella," computers use `if` to execute specific steps only when certain conditions are met. This enables algorithms to adapt and respond to different situations or data inputs, making them much more flexible and powerful.

Module 6 Practice Complete!

Excellent! You've practiced making decisions with `if` statements. Conditional logic is key!
Ready for more complex decisions? Try the Advanced Practice for Module 6.