Relational operators

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

Relational operators

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What type of value does the expression Score > 50 give?
A BOOLEAN (TRUE or FALSE)
B INTEGER (a number)
2. Which operator means 'not equal to' in IGCSE pseudocode?
A <>
B !=
3. Age is 16. What does Age >= 16 give?
A FALSE
B TRUE
4. Age is 16. What does Age > 16 give?
A TRUE
B FALSE
5. A pass mark is 40 or more. Which condition is correct?
A Mark >= 40
B Mark > 40

Match the Pairs

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

Left columnRight column
1Age <> 18 AThe boundary is wrong. A person aged exactly 18 should be allowed, so the test should be Age >= 18 and not Age < 18.
2Score >= 50 BMark < 40
3Check that Mark is below 40 only, so a Mark of exactly 40 gives FALSE CTRUE when Age is not equal to 18, otherwise FALSE
4Check whether Password is exactly the same as the stored value Secret DTRUE when Score is 50 or more, so 50 itself gives TRUE
5IF Age != 18 THEN E!= is not a pseudocode operator. 'Not equal to' is written <>, so it should be IF Age <> 18 THEN.
6IF Age < 18 THEN // must be 18 or over to vote FPassword = Secret

Definitions

= < <= > >= <>

Fill in the Blanks

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

1.
IF Mark __ 0 THEN OUTPUT "Not zero" ENDIF
2.
IsAdult ← Age _ 17
3.
IF Age __ 12 THEN OUTPUT "Child" ENDIF
4.
IF Colour _ "Red" THEN OUTPUT "Stop" ENDIF
5.
WHILE Count _ 10 DO Count ← Count + 1 ENDWHILE

Spot the Error

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

Question 1
A INPUT Age
B IF Age => 18 THEN
C OUTPUT "Adult"
D ENDIF
Question 2
A INPUT Guess
B IF Guess != 7 THEN
C OUTPUT "Wrong"
D ENDIF
Question 3
A INPUT Mark
B IF Mark > 50 THEN
C OUTPUT "50 or more: pass"
D ENDIF
Question 4
A INPUT Money
B Cost ← 5
C IF Money <= Cost THEN
D OUTPUT "Can buy"
E ENDIF
Question 5
A WHILE Lives < 0 DO
B Lives ← Lives - 1
C ENDWHILE
D OUTPUT "Game over"

Answer Key

Relational operators
Section A: Quick Questions
Q1
A — BOOLEAN (TRUE or FALSE)
Q2
A — <>
Q3
B — TRUE
Q4
B — FALSE
Q5
A — Mark >= 40
Section B: Match the Pairs
Q1
Age <> 18 → TRUE when Age is not equal to 18, otherwise FALSE
Q2
Score >= 50 → TRUE when Score is 50 or more, so 50 itself gives TRUE
Q3
Check that Mark is below 40 only, so a Mark of exactly 40 gives FALSE → Mark < 40
Q4
Check whether Password is exactly the same as the stored value Secret → Password = Secret
Q5
IF Age != 18 THEN → != is not a pseudocode operator. 'Not equal to' is written <>, so it should be IF Age <> 18 THEN.
Q6
IF Age < 18 THEN // must be 18 or over to vote → The boundary is wrong. A person aged exactly 18 should be allowed, so the test should be Age >= 18 and not Age < 18.
Section C: Definitions
Q1
= < <= > >= <> — Relational operators compare two values and give a BOOLEAN result (TRUE or FALSE). = equal, <> not equal, < less than, <= less or equal, > greater than, >= greater or equal.
Section D: Fill in the Blanks
Q1
IF Mark <> 0 THEN OUTPUT "Not zero" ENDIF
Q2
IsAdult ← Age > 17
Q3
IF Age <= 12 THEN OUTPUT "Child" ENDIF
Q4
IF Colour = "Red" THEN OUTPUT "Stop" ENDIF
Q5
WHILE Count < 10 DO Count ← Count + 1 ENDWHILE
Section E: Spot the Error
Q1
B — => is not a relational operator in pseudocode. 'Greater than or equal to' is written >=, so the line should be IF Age >= 18 THEN.
Q2
B — Pseudocode uses <> for 'not equal to', not !=. The line should be IF Guess <> 7 THEN.
Q3
B — Boundary error. A mark of exactly 50 should pass, but > excludes 50. It should be >= 50 so the boundary value is included.
Q4
C — The operator points the wrong way. You can buy the item when Money is greater than or equal to Cost, so it should be IF Money >= Cost THEN.
Q5
A — Lives is never less than 0 while the player is still alive, so the condition is FALSE at once and the loop never runs. It should be WHILE Lives > 0 DO.