Episode 8 of 29

If Statements

Learn how to make decisions in your code using if, elif, and else statements.

If statements let your program make decisions based on conditions.

Basic If Statement

age = 18
if age >= 18:
    print("You are an adult")
else:
    print("You are a minor")

If / Elif / Else

score = 85
if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
else:
    grade = "F"
print("Grade:", grade)

Logical Operators

if age > 18 and income > 30000:
    print("Eligible")

if age < 13 or age > 65:
    print("Discount")