Module 7: Practice Zone - Decisions!

Let's practice making choices in code with `if` and `else`.

Anatomy of an `if/else` Statement

This structure lets code choose between two paths. Click on the highlighted parts below to understand their roles.

if temperature > 25:
print("It's hot!")
else:
print("It's cool.")

Identify all 5 parts!

Predict the Path

Look at the code and the value of the variable. Which block of code (`if` or `else`) will run? Click the correct button.

Variable value: score = 75
if score >= 60:
print("Pass")
else:
print("Fail")

Build an `if/else` Statement

Drag the pieces into the dark area to build an `if/else` statement that checks if `count` is 0. Print "Empty" if it is, and "Not Empty" otherwise. Order and keywords matter! (Indentation is shown visually but not strictly enforced by drag placement).

Drop pieces here in the correct order...

Your Turn: Make a Decision

Write an `if/else` statement in the editor. Check if a variable named `age` is 18 or greater. If it is, print "Adult". Otherwise, print "Minor". We'll test it for you!

Output will appear here...

Mini Missions: Decisions!

Time for some quick coding challenges using `if/else`. Complete the tasks below.

Mission 1: Positive or Not?

Given a variable `number`, write an `if/else` statement. If `number` is greater than 0, print "Positive". Otherwise, print "Not positive".

Mission 2: Access Granted?

Given a variable `password`, write an `if/else` statement. If `password` is exactly equal to the string "open_sesame", print "Access Granted". Otherwise, print "Access Denied".

Mission 3: Even or Odd?

Given a variable `value`, write an `if/else` statement using the modulo operator (`%`). If `value % 2` equals 0, print "Even". Otherwise, print "Odd".

Module 7 Practice Complete!

Great job practicing `if/else` statements! You're getting better at controlling the flow of your code.
Ready for more complex decisions? Try the Advanced Practice for Module 7!