5. If Statements
1. Simple Definition & Meaning
An If Statement is a way to make the computer make decisions. It tells the computer: "IF this is true, do this. OTHERWISE, do that."
2. Real-World Examples
- Example 1: IF it is raining, take an umbrella. ELSE, wear sunglasses.
- Example 2: IF your score in a game is over 100, you win! ELSE, you keep playing.
3. Important Points
- We use
==to check if two things are exactly equal (likescore == 100). - We use
if,elif(else if), andelseto chain decisions. - Don't forget the colon
:at the end of the if statement!
📝 Exam Notes (Quick Revision)
- Syntax:
if condition:followed by indented code block. - Operators:
==(Equal),!=(Not equal),>(Greater than),<(Less than). - Elif/Else: Use
eliffor multiple conditions, andelseas a catch-all at the end.