Module 2

Combining conditions

Building more complex decisions.

Complex decisions

You can combine and, or, and not to build more complex conditions. Use parentheses to make the order clear.

Python
temperature = 25
humidity = 80
if (temperature > 20 and temperature < 30) and not humidity > 70:
    print("Ideal")
else:
    print("Not ideal")
Not ideal

Read the condition carefully: the temperature must be between 20 and 30, AND the humidity must NOT be above 70. The humidity is 80, so the condition is false.

Your task

Combine conditions

  • Check if temperature (25) is between 20 and 30 AND humidity (60) is < 70.