Module 7: Advanced Practice - More Choices

Let's explore `elif` for multiple conditions and more complex decision making.

Anatomy of `if/elif/else`

When you need more than two options, `elif` (else if) comes to the rescue. Click the parts to see their roles.

if grade >= 90:
print("Grade: A")
elif grade >= 80:
print("Grade: B")
else:
print("Grade: C or below")

Identify all 7 parts!

Predict the Correct Path

With `elif`, only ONE block will run – the first one whose condition is True. Which block runs for the given `value`?

Variable value: value = -5
if value > 0:
print("Positive")
elif value == 0:
print("Zero")
else:
print("Negative")

Build with `elif`

Drag the pieces to check a `score`: print "Gold" if >= 95, "Silver" if >= 90, or "Bronze" otherwise. Remember the order: `if`, then `elif`, then `else`.

Drop pieces here for the if/elif/else structure...

Your Turn: Multi-way Logic

Write an `if`/`elif`/`else` statement. Given a variable `temp`, print "Freezing" if below 0, "Cold" if 0 to 10 (inclusive), or "Moderate" otherwise.

Output will appear here...

Advanced Mini Missions

Time for slightly trickier challenges involving `elif`, `and`, or nested logic.

Mission 1: Number Ranges

Given `x`, print "Small" if less than 10, "Medium" if 10 to 50 (inclusive), or "Large" if over 50. Use `if`/`elif`/`else`.

Mission 2: Simple Login

Given `username` and `password`, print "Login Success" only if `username` is "admin" AND `password` is "pass123". Otherwise, print "Login Failed". (Hint: Use `and` in the `if` condition).

Mission 3: Nested Check

Given `num`, first check if it's positive. If it is, then check if it's even or odd (print "Positive Even" or "Positive Odd"). If it's not positive, print "Not Positive". (Hint: `if` inside an `if`).

Module 7 Advanced Practice Complete!

Excellent! You've tackled `elif` and more complex decision structures.
Feel free to review the Practice again, watch the Video Lesson, or proceed to the next module!