Decisions: if, elif, else
5. If, Elif and Else
Conditional statements allow your program to make decisions.
if: Executes code when a condition is true.elif: Checks another condition.else: Executes code when all previous conditions are false.
temperature = 30
if temperature > 35:
print("Too hot!")
elif temperature > 25:
print("Warm temperature")
else:
print("Temperature is normal")
Robotics example:
button = True
if button:
print("LED ON")
else:
print("LED OFF")
