Back to Relational Operations In A Programming Language

Oak National Academy

Lessons written by expert teachers in England, each with slides, a video and quizzes.

Their topic:
Introduction to Python programming · Programming: selection
For your topic:
Relational Operations In A Programming Language · Computer Science - 9210

Use these lessons alongside our lesson note, which covers your syllabus in full.

What this covers in your syllabus

3 lessons from Oak National Academy

Lesson 1 of 3 · Lower secondary, ages 11 to 14

Builds the basics this topic needs

Building a program using control structures

By the end: I can combine sequence, selection and iteration to build a program that uses complex conditions.

Key learning points

  1. Expressions formed using logical operators evaluate to either True or False.
  2. Logical and relational operators can be combined to create complex conditions.
  3. The programming constructs of sequence, selection and iteration can be combined to make more complex programs.

Keywords

condition
an expression that evaluates to True or False
selection
used when there is more than one possible path for a program to follow
iteration
the process of repeating a sequence of instructions within a program loop

A common mistake

Mistake: Learners often get confused between the logic operators AND and OR.

In fact: For an AND statement to return True both inputs must be True. For an OR statement to return True either input can be True.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

Which logical operator in Python would you use to check if at least one of two conditions is True?
Which logical operator in Python would you use to check if both of two conditions are True?
Which of these Python `while` loop conditions will keep the loop running forever, no matter what happens inside the loop?
Which of the following is a potential benefit of combining programming structures?
What is the output of the following Python code? ``` is_weekend = True have_homework = False if is_weekend and not have_homework: print("Time to relax") else: print("Time to study.")```

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

Lesson 2 of 3 · GCSE level, ages 14 to 16

Relational operators

By the end: I can use relational operators as part of selection statements.

Key learning points

  1. Relational operators are used to compare values in expressions.
  2. Expressions either return as True or False.
  3. Relational operators can be used in selection statements.

Keywords

relational operator
compare two values and produce the result of True or False
condition
an expression that evaluates to True or False
selection
used when there is more than one possible path for a program to follow

A common mistake

Mistake: The = operator is used for comparison.

In fact: When using Python for programming the == operator is used for comparison and the = operator is used for assignment. Other languages may not always use these operators for these tasks.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

What do relational operators do in a program?
What is the result of the expression `15 > 12`?
What will be displayed if score = 11 in the following code? ```if score < 5: print("You lose") elif score <= 10: print("Not bad!") else: print("You win!") ```

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

Lesson 3 of 3 · Lower secondary, ages 11 to 14

Builds the basics this topic needs

Using selection

By the end: I can write selection statements that make decisions about which path a program will follow.

Key learning points

  1. Selection is used when there is more than one possible path for a program to follow.
  2. Relational operators can be used to compare the values of expressions.
  3. Expressions formed using relational operators evaluate to either True or False.
  4. Logical expressions can be built using a combination of relational and logical operators.

Keywords

relational operator
compare two values and produce the result of True or False
condition
an expression that evaluates to True or False
selection
used when there is more than one possible path for a program to follow
logical expression
an expression that combines relational and logical operators

A common mistake

Mistake: The = symbol is used to check if a variable is equal to a value (comparison).

In fact: The = symbol is used in Python for assignment. The == operator is used for comparison.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

In Python, which keyword allows you to create a block of code that only executes when a certain condition is true?
Which if statement would correctly check if the variable score is greater than or equal to 80?

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

The wording comes from each publisher. The layout and the links to your syllabus are ours.