ScholaFly

CS12-05 Computer Science Watch

Relational operators

Share to Google Classroom

Watch on YouTube

In this lesson

Relational operators: how to use the six relational operators ==, !=, <, ≤, > and ≥ in code, type them as the keyboard has them. AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Programming basics 5 of 9. More at https://scholafly.com

By the end: Use the six relational operators ==, !=, <, <=, > and >= in code, type them as the keyboard has them (never ≥, never =>), say that every comparison gives a Boolean result of True or False, tell = (store) from == (check), and choose the right operator for an inclusive or exclusive boundary such as 'at least 18' or 'between 1 and 100 inclusive'.

What it covers

  1. 0:00 Intro: relational operators
  2. 0:42 Six relational operators
  3. 2:43 Store or check
  4. 6:32 The edge of a comparison

Key words

About this video

Relational operators | GCSE Computer Science | CS12-05

Relational operators: how to use the six relational operators ==, !=, <, ≤, > and ≥ in code, type them as the keyboard has them.
AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Programming basics 5 of 9.
More at https://scholafly.com

Watch first: CS12-04 - https://youtu.be/T8DtxBsYrZk
Video code: CS12-05 (search "ScholaFly CS12-05")

#GCSEComputerScience #ProgrammingBasics #RelationalOperators

For teachers
This GCSE Computer Science lesson teaches relational operators. By the end, students should be able to use the six relational operators ==, !=, <, ≤, > and ≥ in code, type them as the keyboard has them (never ≥, never =>), say that every comparison gives a Boolean result of True or False, tell = (store) from == (check), and choose the right operator for an inclusive or exclusive boundary such as 'at least 18' or 'between 1 and 100 inclusive'. It works through four worked examples and the mistakes examiners report.

Exam board specification references:
AQA 8525
- 3.2.4
Edexcel 1CP2
- 1.2.3
- 6.5.2
OCR J277
- 2.2.1

Read the transcript

A ride's sign says at least a hundred and twenty centimetres. Does its gate let on a child of exactly a hundred and twenty? The sign says yes, but the gate's program checks for greater than a hundred and twenty, so the child is turned away. One missing character, in one line: comparing is easy for a computer, but the edge has to be exactly right. By the end of this one you will know which character the gate got wrong.

A relational operator compares two values, and the result is always True or False. There are six. Two equals signs means equal to. An exclamation mark then an equals sign means not equal to. Less than and greater than are the two arrow shapes, and each can take an equals sign after it. In the two-character ones, the equals sign always comes second. None of them uses the maths signs with a line underneath, because those are not on a keyboard. Whatever goes in, only two results come out. Seven greater than three is True. Two greater than three is False. The result is a Boolean, never yes or no. Here are two comparisons on x: x greater than seven, and x greater than or equal to seven. What does each one give, with x equal to seven? False, then True. Seven is not more than seven, but it is equal to it. One examiner's report gives a figure on this. The second part was not answered as well, with only around twenty-five per cent of the students identifying that a comparison only has two possible values; the most common incorrect response was that there were five possible values. The fix: however many numbers a comparison looks at, the answer is True or False, two values and no more.

One equals sign and two equals signs do different jobs. In Python and in one course's reference language, a single equals sign stores a value, and a double one checks whether two values are equal. One course's pseudo-code compares with a single sign, because it stores with an arrow, so read the notation you are given. A check on strings is exact. The text yes with a small y is not equal to Yes with a capital, so that comparison gives False. Three if lines follow, each with one slip. Line one: if mark, maths greater-or-equal sign, fifty. Line two: if mark, equals then greater than, fifty. Line three: if answer, single equals, the text yes. What is wrong with each of those three if lines? The first is not code at all: that symbol is not on a keyboard, so it is typed as two characters. The second has its pair in the wrong order, and the equals must come second. The third stores rather than checks, so it needs the double equals. One examiner's report: Students continue to use mathematical symbols incorrectly, such as the greater than or equal to sign, which would not work in programming languages. Also, the order in which the symbols are appearing would cause issues if programmed in an I D E, for example equals then greater than, instead of greater than then equals. Some students were not gaining marks due to confusing the symbols, using greater than instead of less than and vice versa. An I D E is the program you write code in. The fix is to type only what the keyboard has, equals second, and to check the direction the arrow points: its wide, open side faces the bigger value. Questions also ask you to point at the relational operator inside a given line of code. If score greater than fifty then: which part is the relational operator? Only the greater than symbol. Copying out everything does not show which part you mean. The same report records how that went. Just over seventy-five per cent of students were able to identify where the arithmetic operator was for the algorithm, this dropped to only sixty per cent being able to correctly identify the relational operator. A common error included writing the whole of line five, which didn't show that the student understood which part was the answer. So point at the symbol on its own, and say it in words, reading left to right.

Inclusive means the end value itself counts. At least eighteen includes eighteen, so it needs greater than or equal to. More than eighteen leaves eighteen out, so it needs greater than. Up to and including a hundred is less than or equal to. Under a hundred is less than. The test is to run the edge value itself through the condition and see whether it gets through. Which operator does the rule temperature below nought need? Less than. Nought does not count as below nought, so the strict operator fits. Now a harder one: password not equal to letmein. How is that written? Password, an exclamation mark and an equals sign, then letmein inside quotation marks, because it is a string. Back at the ride, try this: what one change lets the child at a hundred and twenty on? Greater than becomes greater than or equal to. The edge value is then included, and the child rides. One examiner's report, on a question about a range of valid numbers, says this. Another frequent error involved misunderstanding the inclusivity of the boundaries. Some candidates used num greater than one AND num less than a hundred, which would exclude valid inputs of one and a hundred. A range like one to a hundred needs two comparisons, and joining them is the job of the video AND, OR and NOT in a condition. Here the point is the operators. The fix is to ask whether each end number counts, then test that number through the condition.

Six symbols, a two-value answer and an edge to get right: here they are on conditions new to this video. Write the condition for a mark of at most forty. Mark less than or equal to forty. At most includes forty itself. Here's one to evaluate: y holds ten. What does y not equal to ten give? False. y does equal ten, so the not-equal check fails. Another: how many possible results can comparing two prices give? Two, True and False, whatever the prices are. One more ride: anyone under a hundred and ninety centimetres. Which operator? The strict less than sign. Under leaves a hundred and ninety itself out, so the gate needs the strict one.

If you have the six symbols covered, edges included, a tap on the thumbs up ticks this video off for good. If the edges still feel fiddly, save it; nobody gets boundaries right first time, and that is normal.

Next in the chapter: AND, OR and NOT in a condition. Hopefully that's next in your feed, but if not, search for ScholaFly C S twelve, oh six.

Every other video is on scholafly.com too, easy to search by video code or by keyword. Whatever you're revising, go there and have a look, or, watch the next video.

Related terms

For: AQA GCSE 8525, Edexcel GCSE 1CP2, OCR GCSE J277

On the specification

BoardSpecStatement
AQA GCSE 85253.2.4Use the relational operators equal to, not equal to, less than, greater than, less than or equal to and greater than or equal to.
Edexcel GCSE 1CP21.2.3Algorithms
Edexcel GCSE 1CP26.5.2Write programs using relational operators.
OCR GCSE J2772.2.1Programming fundamentals
For teachers

This GCSE Computer Science lesson teaches relational operators. By the end, students should be able to use the six relational operators ==, !=, <, ≤, > and ≥ in code, type them as the keyboard has them (never ≥, never =>), say that every comparison gives a Boolean result of True or False, tell = (store) from == (check), and choose the right operator for an inclusive or exclusive boundary such as 'at least 18' or 'between 1 and 100 inclusive'. It works through four worked examples and the mistakes examiners report.