Lesson 7: Conditional Statements – if, elif, else

1. Making Decisions with if

if statements run code only if a condition is True.

age = 18
if age >= 18:
    print("You can vote!")

else runs if condition is False:

if age >= 18:
    print("Adult")
else:
    print("Minor")

Exercise 1

What prints if score = 85?
if score >= 90:
    print("A")
elif score >= 80:
    print("B")
else:
    print("C")

2. elif & Nested Conditions

elif = else if — checks additional conditions.

Example:

temp = 25
if temp > 30:
    print("Hot")
elif temp > 20:
    print("Warm")
else:
    print("Cool")

Nested:

if age >= 18:
    if has_id:
        print("Allowed")
    else:
        print("Need ID")

Exercise 2

What prints if x = 10?

if x > 15:
    print("Big")
elif x > 5:
    print("Medium")
else:
    print("Small")
# Answer: 

Exercise 3

Which conditions print "Pass"? (score = 75)
← Previous Lesson (6) Next Lesson (8) →