Use
if statements to run code only when a condition is true.
age = 18
if age >= 18:
print("You are an adult")
Important: Python uses indentation (4 spaces) to define code blocks!
age = 15
if age >= 18:
print("You can vote")
else:
print("Too young to vote")
For multiple conditions:
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
Interactive Visualization