The common Boolean operators AND, OR and NOT
2.2.1 Programming Fundamentals
Practise exam questionsProgramming Fundamentals — Note 6 of 6
== != <> <= >= < > '
Boolean operators (AND, OR, NOT) work with Boolean values (True/False) and are used in conditions to control program flow. Comparison operators (==, !=, <, >, <=, >=) compare values and return True or False. These are combined in selection and iteration statements to create complex conditions.
True only if BOTH conditions are True.True if EITHER condition (or both) is True.True = False, NOT False = True.== checks if two values are equal; != checks if they are not equal.< less than, > greater than, <= less than or equal to, >= greater than or equal to. Use >= not ≥ in code.if A AND (B OR C) → customer is 15+ AND has ticket OR has money.5 == 5 is True, 5 != 2 is True, 5 < 2 is False, 5 <= 4 is False.and, or, not). OCR Exam Reference Language writes them in uppercase (AND, OR, NOT).if room == "basic" or "premium" is WRONG. You must compare the variable each time: if room == "basic" or room == "premium".if room != "basic" or room != "premium" is always True. Use AND instead: if room != "basic" and room != "premium".if SystemArmed AND DoorActive OR WindowActive will sound the alarm when the window is active even if the system is NOT armed! Fix with BRACKETS: if SystemArmed AND (DoorActive OR WindowActive).== is a COMPARISON operator, + is ARITHMETIC, DIV is ARITHMETIC, > is COMPARISON. You may be asked to classify operators.age = 20
has_ticket = True
# AND: both must be True
if age >= 18 and has_ticket:
print("Entry allowed")
# OR: at least one must be True
if age < 12 or age > 65:
print("Discount applies")
# NOT: reverses the value
logged_in = False
if not logged_in:
print("Please log in")# and: BOTH conditions must be True
age = int(input("Enter your age: "))
if age >= 13 and age <= 19:
print("You are a teenager")
# or: AT LEAST ONE condition must be True
day = input("Enter the day: ")
if day == "Saturday" or day == "Sunday":
print("It's the weekend!")
# not: reverses a Boolean value
logged_in = False
if not logged_in:
print("Please log in first.")Ready to test yourself?
Practise 2.2.1 questions