Lesson 6: Making Decisions (If/Else)

⏱ ~20 min Lesson 6 of 10 💚 Free

Programs need to make decisions. Should the character jump? Did the player win? Is the answer correct? The if statement lets your program choose different paths.

Key Concepts

The if Statement

if condition: runs code only when the condition is True. The indented code below the if only runs if the condition passes. If not, Python skips it.

else and elif

else: runs when the if condition is False. elif: (short for 'else if') lets you check multiple conditions in order. Python checks each one top to bottom and runs the first that matches.

Comparison Operators

== means equal to. != means not equal. > greater than. < less than. >= greater than or equal. <= less than or equal. These all return True or False.

🆕 Try It: Live Python

Try it — edit the code and click Run!

✅ Check Your Understanding

1. What does elif mean?

2. What does == check?

3. What runs after else:?