Logical operator NOT

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

Logical operator NOT

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is the value of NOT TRUE?
A TRUE
B FALSE
2. Score is 62. What does NOT (Score >= 50) evaluate to?
A FALSE
B TRUE
3. Score is 35. What does NOT (Score >= 50) evaluate to?
A TRUE
B FALSE
4. Found is a BOOLEAN variable set to FALSE. What is NOT Found?
A FALSE
B TRUE
5. Which condition means the same as NOT (Score >= 50)?
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
1NOT (Score >= 50) ATRUE when the BOOLEAN variable Found holds FALSE
2NOT Found BIF NOT Found THEN OUTPUT "Not found" ENDIF
3NOT reverses a condition, so NOT FALSE gives TRUE CTRUE only when Score is below 50, because NOT reverses the condition
4NOT (Age = 18) does the same job as the not-equal operator <> DNOT (Score >= 50) is TRUE for scores below 50, so the message should be Fail, not Pass.
5IF NOT Score >= 50 THEN OUTPUT "Fail" ENDIF EIF Age <> 18 THEN OUTPUT "Not 18" ENDIF
6IF NOT (Score >= 50) THEN OUTPUT "Pass" ENDIF FThe condition Score >= 50 is not in brackets, so it is unclear what NOT applies to. It should be NOT (Score >= 50).

Definitions

NOT

Fill in the Blanks

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

1.
IF ___ (Score >= 50) THEN OUTPUT "Resit needed" ENDIF
2.
IF NOT _____ THEN OUTPUT "Keep searching" ENDIF
3.
Same ← NOT (Age = 18) Same2 ← Age __ 18
4.
Pass ← NOT (Score _ 50) OUTPUT Pass
5.
Result ← NOT _____ OUTPUT Result

Spot the Error

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

Question 1
A DECLARE Score : INTEGER
B DECLARE Fail : BOOLEAN
C INPUT Score
D Fail <- (Score >= 50)
E OUTPUT Fail
Question 2
A IF NOT (Age >= 18)
B OUTPUT "Minor"
C ENDIF
Question 3
A DECLARE Found : BOOLEAN
B Found <- FALSE
C OUTPUT "Searching..."
D IF Found NOT THEN
E OUTPUT "Not found"
F ENDIF
Question 4
A DECLARE Found : BOOLEAN
B Found = FALSE
C IF NOT Found THEN
D OUTPUT "Missing"
E ENDIF
Question 5
A DECLARE Answer : STRING
B INPUT Answer
C IF NOT (Answer <> "Y") THEN
D OUTPUT "Not yes"
E ENDIF

Answer Key

Logical operator NOT
Section A: Quick Questions
Q1
B — FALSE
Q2
A — FALSE
Q3
A — TRUE
Q4
B — TRUE
Q5
A — Score < 50
Section B: Match the Pairs
Q1
NOT (Score >= 50) → TRUE only when Score is below 50, because NOT reverses the condition
Q2
NOT Found → TRUE when the BOOLEAN variable Found holds FALSE
Q3
NOT reverses a condition, so NOT FALSE gives TRUE → IF NOT Found THEN OUTPUT "Not found" ENDIF
Q4
NOT (Age = 18) does the same job as the not-equal operator <> → IF Age <> 18 THEN OUTPUT "Not 18" ENDIF
Q5
IF NOT Score >= 50 THEN OUTPUT "Fail" ENDIF → The condition Score >= 50 is not in brackets, so it is unclear what NOT applies to. It should be NOT (Score >= 50).
Q6
IF NOT (Score >= 50) THEN OUTPUT "Pass" ENDIF → NOT (Score >= 50) is TRUE for scores below 50, so the message should be Fail, not Pass.
Section C: Definitions
Q1
NOT — A logical operator that reverses a condition: NOT TRUE is FALSE and NOT FALSE is TRUE. For example, NOT (Score >= 50) is TRUE only when Score is below 50.
Section D: Fill in the Blanks
Q1
IF NOT (Score >= 50) THEN OUTPUT "Resit needed" ENDIF
Q2
IF NOT Found THEN OUTPUT "Keep searching" ENDIF
Q3
Same ← NOT (Age = 18) Same2 ← Age <> 18
Q4
Pass ← NOT (Score < 50) OUTPUT Pass
Q5
Result ← NOT FALSE OUTPUT Result
Section E: Spot the Error
Q1
D — NOT is missing. Without it, Fail is TRUE when the score is 50 or more, which is the opposite of what is wanted. It should be Fail <- NOT (Score >= 50).
Q2
A — An IF statement must have THEN after its condition. The line should be IF NOT (Age >= 18) THEN.
Q3
D — NOT is a prefix operator, so it goes before the value it reverses. The line should be IF NOT Found THEN.
Q4
B — = is a comparison, not assignment. Cambridge pseudocode assigns with <-, so the line should be Found <- FALSE.
Q5
C — NOT reverses <>, so NOT (Answer <> "Y") means the same as Answer = "Y". The message would show for a Y. Use NOT (Answer = "Y") or just Answer <> "Y".