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. Which symbol means 'not equal to' in Cambridge pseudocode?
A !=
B <>
2. Which line compares Age with 18 and gives TRUE or FALSE?
A Age = 18
B Age ← 18
3. Age is 16. What is the result of Age >= 16?
A TRUE
B FALSE
4. Score is 50. What is the result of Score < 50?
A FALSE
B TRUE
5. Which line stores the value 7 in the variable Count?
A Count = 7
B Count ← 7

Match the Pairs

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

Left columnRight column
1Age <> 18 AIF Password = "abc123" THEN
2Score >= 50 B← assigns a value and cannot compare. Use = in the condition: IF Age = 18 THEN.
3Use = to compare two values and get TRUE or FALSE, not to store a value CTRUE when Score is 50 or more, FALSE when Score is below 50
4Use ← to assign a value to a variable, while = only compares values DTRUE when Age is not equal to 18, FALSE when Age is exactly 18
5IF Mark != 40 THEN E!= is not Cambridge pseudocode. Not equal is written <>, so it should be IF Mark <> 40 THEN.
6IF Age ← 18 THEN FTotal ← 0

Definitions

= < <= > >= <>

Fill in the Blanks

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

1.
IF Age __ 18 THEN OUTPUT "Adult" ENDIF
2.
IF Password __ "abc123" THEN OUTPUT "Wrong password" ENDIF
3.
IF Choice _ 1 THEN OUTPUT "You chose option 1" ENDIF
4.
IsTeen ← Age __ 19 OUTPUT IsTeen
5.
Total _ 0 IF Total = 0 THEN OUTPUT "Empty" ENDIF

Spot the Error

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

Question 1
A INPUT Age
B Adult ← FALSE
C // 18 or over is an adult
D IF Age => 18 THEN
E Adult ← TRUE
F ENDIF
Question 2
A IF Name != "Admin" THEN
B OUTPUT "Access limited"
C ENDIF
Question 3
A WHILE Guess = Secret DO
B INPUT Guess
C ENDWHILE
Question 4
A INPUT Mark
B // 40 or more is a pass
C IF Mark > 40 THEN
D OUTPUT "Pass"
E ENDIF
Question 5
A INPUT Code
B IF Code ← 1234 THEN
C OUTPUT "Welcome"
D ENDIF

Answer Key

Relational operators = < <= > >= <>
Section A: Quick Questions
Q1
B — <>
Q2
A — Age = 18
Q3
A — TRUE
Q4
A — FALSE
Q5
B — Count ← 7
Section B: Match the Pairs
Q1
Age <> 18 → TRUE when Age is not equal to 18, FALSE when Age is exactly 18
Q2
Score >= 50 → TRUE when Score is 50 or more, FALSE when Score is below 50
Q3
Use = to compare two values and get TRUE or FALSE, not to store a value → IF Password = "abc123" THEN
Q4
Use ← to assign a value to a variable, while = only compares values → Total ← 0
Q5
IF Mark != 40 THEN → != is not Cambridge pseudocode. Not equal is written <>, so it should be IF Mark <> 40 THEN.
Q6
IF Age ← 18 THEN → ← assigns a value and cannot compare. Use = in the condition: IF Age = 18 THEN.
Section C: Definitions
Q1
= < <= > >= <> — Relational operators compare two values and give TRUE or FALSE: = equal, < less, <= at most, > greater, >= at least, <> not equal. Use = to compare, ← to assign.
Section D: Fill in the Blanks
Q1
IF Age >= 18 THEN OUTPUT "Adult" ENDIF
Q2
IF Password <> "abc123" THEN OUTPUT "Wrong password" ENDIF
Q3
IF Choice = 1 THEN OUTPUT "You chose option 1" ENDIF
Q4
IsTeen ← Age <= 19 OUTPUT IsTeen
Q5
Total ← 0 IF Total = 0 THEN OUTPUT "Empty" ENDIF
Section E: Spot the Error
Q1
D — => is not a relational operator in Cambridge pseudocode. 'Greater than or equal to' is written >=, so the line should be IF Age >= 18 THEN.
Q2
A — Cambridge pseudocode writes 'not equal to' as <>, not !=. The line should be IF Name <> "Admin" THEN.
Q3
A — The loop must keep asking while the guess is NOT the secret. Using = would stop the loop at once for a wrong guess. It should be WHILE Guess <> Secret DO.
Q4
C — A mark of exactly 40 should pass, but > leaves 40 out. 'At least 40' needs >=, so the line should be IF Mark >= 40 THEN.
Q5
B — ← assigns a value, but an IF needs a comparison that gives TRUE or FALSE. Use = to compare: IF Code = 1234 THEN.