Computing
Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE ## Lesson Video 15

• Watch the Lesson video
Make notes on your notes sheet.
• Make notes on your notes sheet.
• Complete the learning activities
Make any notes on your notes sheet.
• Check the Learning outcomes

## What do I need to Learn?

 I need to learn how to understand and know how to use selection in a computer program. I am familiar with and able to use the operators: equal to, not equal to, less than, greater than, less than or equal to, greater than or equal to in a computer program. I am familiar with and able to use the NOT boolean operator a computer program. I am familiar with and able to use the AND boolean operator a computer program. I am familiar with and able to use the OR boolean operator a computer program.

## Key Terms

Boolean Boolean operators Selection Condition Branch If Statement Evaluate

## Comparison operators

Comparison operators are used to compare values. It either returns `True` or `False` according to the condition.

Comparision operators in Python
Operator Meaning Example
> Greater that - True if left operand is greater than the right x > y
< Less that - True if left operand is less than the right x < y
== Equal to - True if both operands are equal x == y
!= Not equal to - True if operands are not equal x != y
>= Greater than or equal to - True if left operand is greater than or equal to the right x >= y
<= Less than or equal to - True if left operand is less than or equal to the right x <= y

### Example #1: Comparison operators in Python

Python uses operators to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated. For example:

Run the above code ito see what it does.

### Example #2: Comparison operators in Python

Run the above code in python and then change the question marks in the comments to say what happens when the code is run.

Notice that variable assignment is done using a single equals operator "=", whereas comparison between two variables is done using the double equals operator "==". The "not equals" operator is marked as "!=".

## Exercise

Change the above code so that it prints out the following:

• x > y is True
• x < y is False
• x == y is False
• x != y is True
• x >= y is True
• x <= y is False    