Today I learned about logical conditions in Python. There are three logical conditions:
- And – means that both conditions must be true
- Or – means that one of the conditions must be true
- Not – inverts the condition
# logical operators = Evaluate multiple conditions. (or, and, not)
# or = At least one condition must be true.
# and = Both conditions must be true.
# not = Inverts the condition. (not false, not true)
temp = 25
is_sunny = False
if temp >= 28 and is_sunny:
print("It is HOT outside")
print("It is SUNNY")
elif temp <= 0 and is_sunny:
print("It is COLD outside")
print("It is SUNNY")
elif 28 > temp > 0 and is_sunny:
print("It is WARM outside")
print("It is SUNNY")
elif temp >= 28 and not is_sunny:
print("It is HOT outside")
print("It is CLOUDY")
elif temp <= 0 and not is_sunny:
print("It is COLD outside")
print("It is CLOUDY")
elif 28 > temp > 0 and not is_sunny:
print("It is WARM outside")
print("It is CLOUDY")
Leave a Reply