Python beginner Diary Day 012: Logical Conditions

Today I learned about logical conditions in Python. There are three logical conditions:

  1. And – means that both conditions must be true
  2. Or – means that one of the conditions must be true
  3. 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")

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *