← All lessons

Lesson 03

Conditions

Programs make decisions with if statements. If the condition is True, the indented block runs.

Indentation matters in Python — the code inside an if must be indented (usually 4 spaces).

Add elif for extra checks and else for everything else. Comparisons use ==, !=, <, >, <=, >=.

score = 85

if score >= 90:
    print("Grade: A")
elif score >= 80:
    print("Grade: B")
elif score >= 70:
    print("Grade: C")
else:
    print("Keep practicing!")

Check your understanding

Which operator compares two values for equality?

CHALLENGE

Set n to 7. Use if/else to print Even or Odd depending on n.

Practice →
Next: Loops →