Programming constructs - CCEABoolean operators

Computer programs use data stores to organise the different types of data they contain. Data stores can be either a constant, variable or an array, and contain inputs, outputs, functions, instructions, sequences and more.

Part ofDigital Technology (CCEA)Digital development concepts (programming)

Boolean operators

A data type is a binary that can have one of two possible values, 0 (False) or 1 (True). We can combine Booleans using Boolean operators AND, OR, NOT.

Order of operations

The rules of programming follow the same rules as maths in terms of the order in which operators are carried out.

They follow the rules of BODMAS:

BRACKETS/ORDERS/DIVIDE/MULTIPLY/ADD/SUBTRACT

Operators in brackets are carried out first, then orders like powers and roots, then division, multiplication, addition and, finally, subtraction.

For example, Order of Operations in programming a Celsius to Fahrenheit conversion:

  1. celsius = float(input('Enter temperature celsius: '))
  2. fahrenheit = celsius * 9/5 + 32
  3. print(str(celsius) + ' = ' + str(fahrenheit))

Line 1: The user is asked to input a value. This value is stored in the Celsius variable as a float.

Line 2: BODMAS – Division (9/5 = 1.8), Multiplication (1.8 * Celsius), Addition (+32).

Line 3: Program outputs the temperature in Celsius and Fahrenheit.

Operator Name and descriptionExample
ANDBoth operands (inputs) need to be True for the result to be Truea = 5, b = 6: a > 3 AND b > 3 = True
ORIf either or both of the operands are true then the result will be Truea = 5, b = 6: a >= 6 OR b >=6 = True
NOTThe result will be the opposite of the operand givena = False, NOT a = True
==Is equal to – the left operand is equal to the right2 == 2 would be True
<> or !=Is not equal to – the two operands are not equal2 != 1 would be True
<Is less than – the left operand is less than the right3 < 6 would be True
>Is greater than – the left operand is greater than the right2 > 5 would be False
<=Is less than or equal to – the left operand is less than or equal to the right3 <= 4 would be True
>=Is greater than or equal to – the left operand is greater than or equal to the right3 >= 5 would be False
OperatorAND
Name and descriptionBoth operands (inputs) need to be True for the result to be True
Examplea = 5, b = 6: a > 3 AND b > 3 = True
OperatorOR
Name and descriptionIf either or both of the operands are true then the result will be True
Examplea = 5, b = 6: a >= 6 OR b >=6 = True
OperatorNOT
Name and descriptionThe result will be the opposite of the operand given
Examplea = False, NOT a = True
Operator==
Name and descriptionIs equal to – the left operand is equal to the right
Example2 == 2 would be True
Operator<> or !=
Name and descriptionIs not equal to – the two operands are not equal
Example2 != 1 would be True
Operator<
Name and descriptionIs less than – the left operand is less than the right
Example3 < 6 would be True
Operator>
Name and descriptionIs greater than – the left operand is greater than the right
Example2 > 5 would be False
Operator<=
Name and descriptionIs less than or equal to – the left operand is less than or equal to the right
Example3 <= 4 would be True
Operator>=
Name and descriptionIs greater than or equal to – the left operand is greater than or equal to the right
Example3 >= 5 would be False