Logical operator AND

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

Logical operator AND

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Age <- 15. What does (Age >= 13) AND (Age <= 19) evaluate to?
A TRUE
B FALSE
2. Which statement about AND is correct?
A TRUE when at least one condition is TRUE
B TRUE only when both conditions are TRUE
3. Age <- 11. What does (Age >= 13) AND (Age <= 19) evaluate to?
A FALSE
B TRUE
4. Which condition correctly checks that Mark is in the range 0 to 100?
A Mark >= 0 AND <= 100
B Mark >= 0 AND Mark <= 100
5. Score <- 50. What does (Score > 50) AND (Score < 100) evaluate to?
A FALSE
B TRUE

Match the Pairs

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

Left columnRight column
1Age >= 13 AND Age <= 19 AThe second condition is incomplete. Each side of AND must be a full condition, so Age is missing before <= 19.
2Score > 50 AND Score < 80 AND Passed = TRUE BOR is used instead of AND. With OR almost every age is TRUE, so it does not check the 13 to 19 range.
3Check that a mark is in the range 0 to 100 using AND CTRUE only when the age is from 13 to 19 inclusive, because both conditions must be TRUE
4If either condition is FALSE, the whole AND condition is FALSE DIF 15 > 10 AND 4 > 9 THEN
5IF Age >= 13 AND <= 19 THEN EA three-part AND that is TRUE only when all three conditions are TRUE
6IF Age >= 13 OR Age <= 19 THEN FIF Mark >= 0 AND Mark <= 100 THEN

Definitions

AND

Fill in the Blanks

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

1.
IF Age >= 13 ___ Age <= 19 THEN OUTPUT "Teenager" ENDIF
2.
IF Age >= 13 AND Age __ 19 THEN OUTPUT "Teenager" ENDIF
3.
IF Score >= 0 AND Score <= 100 THEN OUTPUT "Valid mark" _____
4.
IF Age >= 13 AND Age <= __ THEN OUTPUT "Teenager" ENDIF
5.
IF Num > 0 AND Num < 10 AND ___ <> 5 THEN OUTPUT "OK" ENDIF

Spot the Error

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

Question 1
A IF Age>=13 AND Age>=19 THEN
B OUTPUT "Teen"
C ENDIF
Question 2
A INPUT Num
B Ok <- FALSE
C IF Num>=1 OR Num<=10 THEN
D Ok <- TRUE
E ENDIF
Question 3
A INPUT Age
B IF Age>=13 AND <=19 THEN
C OUTPUT "Teenager"
D ENDIF
Question 4
A INPUT Temp
B INPUT Rain
C IF Temp>20 AND Rain<>0 THEN
D OUTPUT "Warm and dry"
E ENDIF
Question 5
A INPUT A
B INPUT B
C INPUT C
D IF A>5 AND B>5 OR C>5 THEN
E OUTPUT "All above 5"
F ENDIF

Answer Key

Logical operator AND
Section A: Quick Questions
Q1
A — TRUE
Q2
B — TRUE only when both conditions are TRUE
Q3
A — FALSE
Q4
B — Mark >= 0 AND Mark <= 100
Q5
A — FALSE
Section B: Match the Pairs
Q1
Age >= 13 AND Age <= 19 → TRUE only when the age is from 13 to 19 inclusive, because both conditions must be TRUE
Q2
Score > 50 AND Score < 80 AND Passed = TRUE → A three-part AND that is TRUE only when all three conditions are TRUE
Q3
Check that a mark is in the range 0 to 100 using AND → IF Mark >= 0 AND Mark <= 100 THEN
Q4
If either condition is FALSE, the whole AND condition is FALSE → IF 15 > 10 AND 4 > 9 THEN
Q5
IF Age >= 13 AND <= 19 THEN → The second condition is incomplete. Each side of AND must be a full condition, so Age is missing before <= 19.
Q6
IF Age >= 13 OR Age <= 19 THEN → OR is used instead of AND. With OR almost every age is TRUE, so it does not check the 13 to 19 range.
Section C: Definitions
Q1
AND — AND joins two conditions and is TRUE only when both are TRUE, e.g. Age >= 13 AND Age <= 19. If either condition is FALSE, the whole condition is FALSE.
Section D: Fill in the Blanks
Q1
IF Age >= 13 AND Age <= 19 THEN OUTPUT "Teenager" ENDIF
Q2
IF Age >= 13 AND Age <= 19 THEN OUTPUT "Teenager" ENDIF
Q3
IF Score >= 0 AND Score <= 100 THEN OUTPUT "Valid mark" ENDIF
Q4
IF Age >= 13 AND Age <= 19 THEN OUTPUT "Teenager" ENDIF
Q5
IF Num > 0 AND Num < 10 AND Num <> 5 THEN OUTPUT "OK" ENDIF
Section E: Spot the Error
Q1
A — The upper limit of the range should use <=. With Age>=19 the range check is wrong, so the correct condition is Age>=13 AND Age<=19.
Q2
C — A range check needs AND so both conditions must be TRUE. With OR every number passes. It should be IF Num>=1 AND Num<=10 THEN.
Q3
B — Each side of AND must be a complete condition. <=19 is missing the variable, so it should be Age<=19.
Q4
C — Warm and dry needs Rain to equal 0. Rain<>0 would be TRUE on a wet day. It should be Temp>20 AND Rain=0.
Q5
D — To check that all three values are above 5, every condition must be joined with AND. With OR, C>5 alone makes the condition TRUE. It should be A>5 AND B>5 AND C>5.