AND, OR and NOT

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

AND, OR and NOT

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement about AND is correct?
A Age >= 13 AND Age <= 19 is true if either test is true
B Age >= 13 AND Age <= 19 is true only if both tests are true
2. Which statement about OR is correct?
A Day = "Sat" OR Day = "Sun" is true if at least one test is true
B Day = "Sat" OR Day = "Sun" is true only if both tests are true
3. Number is 5. Which result is correct for Number >= 1 AND Number <= 10?
A FALSE
B TRUE
4. Number is 15. Which result is correct for Number >= 1 AND Number <= 10?
A FALSE
B TRUE
5. Which is the correct range test for a number from 1 to 10 inclusive?
A IF Number >= 1 AND Number <= 10 THEN
B IF Number >= 1 OR Number <= 10 THEN

Match the Pairs

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

Left columnRight column
1IF Age >= 13 AND Age <= 19 THEN AIF Day = "Sat" OR Day = "Sun" THEN
2IF NOT (Score > 50) THEN BTrue only when both conditions are true, so Age is in the range 13 to 19
3OR needs only one condition to be true, so a Day of Saturday or Sunday passes COR is used instead of AND, so the test is true for every number. A range test needs both conditions true, so use AND.
4A range test checks that Number is at least 1 and at most 10 by joining two comparisons with AND DIF Number >= 1 AND Number <= 10 THEN
5IF Number >= 1 OR Number <= 10 THEN EThe second condition is incomplete because Age is missing after AND. Each side of AND must be a full condition: Age <= 19.
6IF Age >= 13 AND <= 19 THEN FReverses the condition, so it is true when Score is 50 or less

Definitions

AND, OR, NOT

Fill in the Blanks

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

1.
IF Number >= 1 ___ Number <= 10 THEN OUTPUT "Valid" ENDIF
2.
IF Answer = "Y" __ Answer = "y" THEN OUTPUT "Yes" ENDIF
3.
IF ___ Found THEN OUTPUT "Not found" ENDIF
4.
IF Number >= 1 AND Number __ 10 THEN OUTPUT "In range" ENDIF
5.
IF Score < 0 __ Score > 100 THEN OUTPUT "Invalid" ENDIF

Spot the Error

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

Question 1
A DECLARE Num : INTEGER
B INPUT Num
C IF Num >= 1 OR Num <= 10
D THEN OUTPUT "In range"
E ENDIF
Question 2
A INPUT Age
B IF Age >= 13 AND <= 19
C THEN OUTPUT "Teenager"
D ENDIF
Question 3
A INPUT Mark
B IF Mark >= 0 AND Mark <= 100
C THEN OUTPUT "Valid"
D ELSE OUTPUT Invalid
E ENDIF
Question 4
A Found ← FALSE
B INPUT Name
C IF Name = "Ali" OR Name = "Bo"
D THEN Found = TRUE
E ENDIF
Question 5
A INPUT Raining
B IF Raining NOT THEN
C OUTPUT "Go outside"
D ENDIF

Answer Key

AND, OR and NOT
Section A: Quick Questions
Q1
B — Age >= 13 AND Age <= 19 is true only if both tests are true
Q2
A — Day = "Sat" OR Day = "Sun" is true if at least one test is true
Q3
B — TRUE
Q4
A — FALSE
Q5
A — IF Number >= 1 AND Number <= 10 THEN
Section B: Match the Pairs
Q1
IF Age >= 13 AND Age <= 19 THEN → True only when both conditions are true, so Age is in the range 13 to 19
Q2
IF NOT (Score > 50) THEN → Reverses the condition, so it is true when Score is 50 or less
Q3
OR needs only one condition to be true, so a Day of Saturday or Sunday passes → IF Day = "Sat" OR Day = "Sun" THEN
Q4
A range test checks that Number is at least 1 and at most 10 by joining two comparisons with AND → IF Number >= 1 AND Number <= 10 THEN
Q5
IF Number >= 1 OR Number <= 10 THEN → OR is used instead of AND, so the test is true for every number. A range test needs both conditions true, so use AND.
Q6
IF Age >= 13 AND <= 19 THEN → The second condition is incomplete because Age is missing after AND. Each side of AND must be a full condition: Age <= 19.
Section C: Definitions
Q1
AND, OR, NOT — Logic operators that combine or reverse conditions: AND needs both true, OR needs one true, NOT reverses a condition. Range test: Number >= 1 AND Number <= 10
Section D: Fill in the Blanks
Q1
IF Number >= 1 AND Number <= 10 THEN OUTPUT "Valid" ENDIF
Q2
IF Answer = "Y" OR Answer = "y" THEN OUTPUT "Yes" ENDIF
Q3
IF NOT Found THEN OUTPUT "Not found" ENDIF
Q4
IF Number >= 1 AND Number <= 10 THEN OUTPUT "In range" ENDIF
Q5
IF Score < 0 OR Score > 100 THEN OUTPUT "Invalid" ENDIF
Section E: Spot the Error
Q1
C — A range test needs both conditions to be true, so it must use AND. With OR, every number passes, because each number is either at least 1 or at most 10. It should be IF Num >= 1 AND Num <= 10.
Q2
B — AND joins two complete conditions, and the second one has lost its variable. Each side needs its own comparison: IF Age >= 13 AND Age <= 19.
Q3
D — Text output must be in double quotes. The line should be ELSE OUTPUT "Invalid".
Q4
D — Assigning a value uses the arrow ←, not =. In Cambridge pseudocode = is a comparison. The line should be THEN Found ← TRUE.
Q5
B — NOT goes in front of the condition it reverses, not after it. It should be IF NOT Raining THEN.