Making decisions with if
Programs become interesting when they react to data. An if statement runs a block only when a condition is true:
temperature = 25
if temperature > 30:
print("Hot")
elif temperature >= 20:
print("Warm")
else:
print("Cold")
Notice the indentation – Python uses it to know which lines belong to the block.
Comparison operators: ==, !=, <, <=, >, >=. Combine conditions with and, or and not.
Try it
Complete the program so that it prints Hot when the temperature is above 30, Warm when it is between 20 and 30 (inclusive) and Cold otherwise. With the given value it should print:
Hot