Relational operators: <, <=, > and >=

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Relational operators: <, <=, > and >=

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Score <- 50. What does Score >= 50 give?
A FALSE, because 50 is not greater than 50
B TRUE, because >= includes the boundary value 50
2. Score <- 50. What does Score > 50 give?
A FALSE, because > leaves out the boundary value
B TRUE, because 50 is the same as 50
3. Age <- 18. What does Age < 18 give?
A TRUE, because 18 is close to 18
B FALSE, because 18 is not less than 18
4. Which condition is TRUE for a student who is exactly 18 years old (Age <- 18)?
A Age <= 18
B Age < 18
5. Which condition correctly tests for a pass mark when 50 or more is a pass?
A Score >= 50
B Score > 50

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Score >= 50 AScore > 50
2Age < 18 BThe < operator leaves out 18, so a person aged exactly 18 gives FALSE. To include 18, use <=.
3To include the boundary value 100 when checking the largest allowed mark, use 'less than or equal to' CTRUE when Score is 50 or more, so a Score of exactly 50 is included
4To test that a value is strictly above the boundary, so 50 itself gives FALSE, use 'greater than' DTRUE only when Age is less than 18, so an Age of exactly 18 is not included
5IF Score => 50 THEN EThe operator is written the wrong way round. Cambridge pseudocode uses >=, not =>.
6IF Age < 18 THEN // 18 should be included FMark <= 100

Definitions

< <= > >=

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF Score __ 50 THEN OUTPUT "Pass" ENDIF
2.
IF Age _ 18 THEN OUTPUT "Under 18" ENDIF
3.
Result <- 50 __ 50 OUTPUT Result
4.
WHILE Lives _ 0 DO Lives <- Lives - 1 ENDWHILE
5.
Adult <- Age __ 18 OUTPUT Adult

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Score : INTEGER
B INPUT Score
C Pass <- FALSE
D IF Score => 50 THEN
E Pass <- TRUE
F ENDIF
Question 2
A DECLARE Age : INTEGER
B INPUT Age
C IF Age <= 18 THEN
D OUTPUT "Under 18"
E ENDIF
Question 3
A DECLARE Mark : INTEGER
B INPUT Mark
C OUTPUT "Pass mark is 50"
D IF Mark > 50 THEN
E OUTPUT "Pass"
F ENDIF
Question 4
A INPUT Temp
B IF Temp =< 0 THEN
C OUTPUT "Freezing"
D ENDIF
Question 5
A DECLARE Age : INTEGER
B INPUT Age
C IF Age <= 18 THEN
D OUTPUT "Adult"
E ENDIF

Answer Key

Relational operators: <, <=, > and >=
Section A: Quick Questions
Q1
B — TRUE, because >= includes the boundary value 50
Q2
A — FALSE, because > leaves out the boundary value
Q3
B — FALSE, because 18 is not less than 18
Q4
A — Age <= 18
Q5
A — Score >= 50
Section B: Match the Pairs
Q1
Score >= 50 → TRUE when Score is 50 or more, so a Score of exactly 50 is included
Q2
Age < 18 → TRUE only when Age is less than 18, so an Age of exactly 18 is not included
Q3
To include the boundary value 100 when checking the largest allowed mark, use 'less than or equal to' → Mark <= 100
Q4
To test that a value is strictly above the boundary, so 50 itself gives FALSE, use 'greater than' → Score > 50
Q5
IF Score => 50 THEN → The operator is written the wrong way round. Cambridge pseudocode uses >=, not =>.
Q6
IF Age < 18 THEN // 18 should be included → The < operator leaves out 18, so a person aged exactly 18 gives FALSE. To include 18, use <=.
Section C: Definitions
Q1
< <= > >= — Relational operators that compare the size of two values and give TRUE or FALSE. < and > leave out the boundary value; <= and >= include it, so 50 >= 50 is TRUE but 50 > 50 is FALSE.
Section D: Fill in the Blanks
Q1
IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Q2
IF Age < 18 THEN OUTPUT "Under 18" ENDIF
Q3
Result <- 50 <= 50 OUTPUT Result
Q4
WHILE Lives > 0 DO Lives <- Lives - 1 ENDWHILE
Q5
Adult <- Age >= 18 OUTPUT Adult
Section E: Spot the Error
Q1
D — There is no => operator in pseudocode. 'Greater than or equal to' is written >= (the > comes first). The line should be IF Score >= 50 THEN.
Q2
C — <= includes the boundary, so an 18-year-old would be told 'Under 18'. Under 18 means strictly less than 18, so use <. The line should be IF Age < 18 THEN.
Q3
D — The pass mark is 50, so a mark of exactly 50 must pass. > leaves out 50 (50 > 50 is FALSE). Use >= to include the boundary: IF Mark >= 50 THEN.
Q4
B — The symbols are in the wrong order. 'Less than or equal to' is written <=, not =<. The line should be IF Temp <= 0 THEN.
Q5
C — The comparison points the wrong way. Adults are aged 18 or MORE, so the condition needs >=, not <=. The line should be IF Age >= 18 THEN.