If Statements
Make decisions in code based on conditions
Example
if age >= 18:
print("You can vote!")
else:
print("Too young to vote")Comprehensive reference guide for Python and Pygame. Learn programming concepts, syntax, and see practical examples for game development.
Make decisions in code based on conditions
if age >= 18:
print("You can vote!")
else:
print("Too young to vote")Chain multiple conditions together
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
print(f"Your grade is: {grade}")Compact way to write simple if-else statements
age = 20
status = "adult" if age >= 18 else "minor"
print(status) # Output: adult
# Multiple ternary operators
result = "positive" if x > 0 else "zero" if x == 0 else "negative"