Writing a range condition precisely

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

Writing a range condition precisely

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is the correct way to write a range check for a mark from 0 to 100?
A Mark >= 0 AND Mark <= 100
B 0 <= Mark <= 100
2. Which condition is TRUE only when Age is inside the range 11 to 16 (inclusive)?
A Age >= 11 AND Age <= 16
B Age >= 11 OR Age <= 16
3. Which condition is TRUE when Mark is OUTSIDE the valid range 0 to 100?
A Mark < 0 OR Mark > 100
B Mark < 0 AND Mark > 100
4. A valid score must include both 1 and 10. Which condition does this?
A Score > 1 AND Score < 10
B Score >= 1 AND Score <= 10
5. Which condition accepts the values 1 to 9 only, so 0 and 10 are NOT valid?
A Num >= 0 AND Num <= 10
B Num > 0 AND Num < 10

Match the Pairs

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

Left columnRight column
1Mark >= 0 AND Mark <= 100 AOR is used instead of AND, so every number passes, even -5 or 500. It should be Mark >= 0 AND Mark <= 100.
2Mark < 0 OR Mark > 100 BValid range check: true only when Mark is from 0 to 100 inclusive, because both comparisons must be true.
3Two separate comparisons joined by AND are used to check a value is within a range, never a chained comparison CAge >= 11 AND Age <= 16
4Use > and < instead of >= and <= when the limits themselves are not allowed (exclusive limits) DTemp > 0 AND Temp < 100
5IF 0 <= Mark <= 100 THEN EThe comparison is chained. Pseudocode needs two comparisons joined by AND: Mark >= 0 AND Mark <= 100.
6IF Mark >= 0 OR Mark <= 100 THEN FInvalid range check: true when Mark is outside 0 to 100, because only one comparison needs to be true.

Definitions

Mark >= 0 AND Mark <= 100

Fill in the Blanks

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

1.
IF Mark >= 0 ___ Mark <= 100 THEN OUTPUT "Valid mark" ENDIF
2.
IF Mark < 0 __ Mark > 100 THEN OUTPUT "Invalid mark" ENDIF
3.
IF Age >= 11 AND Age __ 16 THEN
4.
IF Mark >= 0 AND ____ <= 100 THEN
5.
IF Temp _ 0 AND Temp < 100 THEN

Spot the Error

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

Question 1
A INPUT Mark
B Valid ← FALSE
C IF 0 <= Mark <= 100
D THEN Valid ← TRUE
E ENDIF
Question 2
A INPUT Mark
B Error ← FALSE
C IF Mark < 0 AND Mark > 100
D THEN Error ← TRUE
E ENDIF
Question 3
A // Rating is 1 to 5 inclusive
B INPUT Rating
C IF Rating > 1 AND Rating < 5
D THEN OUTPUT "Valid"
E ENDIF
Question 4
A INPUT Age
B IF Age >= 11 OR Age <= 16
C THEN OUTPUT "Accepted"
D ENDIF
Question 5
A REPEAT
B OUTPUT "Enter mark 0-10"
C INPUT Mark
D UNTIL Mark >= 0 OR Mark <= 10
E ENDIF

Answer Key

Writing a range condition precisely
Section A: Quick Questions
Q1
A — Mark >= 0 AND Mark <= 100
Q2
A — Age >= 11 AND Age <= 16
Q3
A — Mark < 0 OR Mark > 100
Q4
B — Score >= 1 AND Score <= 10
Q5
B — Num > 0 AND Num < 10
Section B: Match the Pairs
Q1
Mark >= 0 AND Mark <= 100 → Valid range check: true only when Mark is from 0 to 100 inclusive, because both comparisons must be true.
Q2
Mark < 0 OR Mark > 100 → Invalid range check: true when Mark is outside 0 to 100, because only one comparison needs to be true.
Q3
Two separate comparisons joined by AND are used to check a value is within a range, never a chained comparison → Age >= 11 AND Age <= 16
Q4
Use > and < instead of >= and <= when the limits themselves are not allowed (exclusive limits) → Temp > 0 AND Temp < 100
Q5
IF 0 <= Mark <= 100 THEN → The comparison is chained. Pseudocode needs two comparisons joined by AND: Mark >= 0 AND Mark <= 100.
Q6
IF Mark >= 0 OR Mark <= 100 THEN → OR is used instead of AND, so every number passes, even -5 or 500. It should be Mark >= 0 AND Mark <= 100.
Section C: Definitions
Q1
Mark >= 0 AND Mark <= 100 — A range check joins two comparisons with AND, so a value is valid only if both are true. Never chain them like 0 <= Mark <= 100. Use OR to test for values outside the range.
Section D: Fill in the Blanks
Q1
IF Mark >= 0 AND Mark <= 100 THEN OUTPUT "Valid mark" ENDIF
Q2
IF Mark < 0 OR Mark > 100 THEN OUTPUT "Invalid mark" ENDIF
Q3
IF Age >= 11 AND Age <= 16 THEN
Q4
IF Mark >= 0 AND Mark <= 100 THEN
Q5
IF Temp > 0 AND Temp < 100 THEN
Section E: Spot the Error
Q1
C — A range check cannot be chained like 0 <= Mark <= 100. It must be two separate comparisons joined by AND: IF Mark >= 0 AND Mark <= 100.
Q2
C — A mark cannot be below 0 and above 100 at the same time, so AND is never true. To test for values outside the range, use OR: IF Mark < 0 OR Mark > 100.
Q3
C — The limits 1 and 5 are allowed (inclusive), so >= and <= are needed. Using > and < wrongly rejects ratings of 1 and 5. It should be IF Rating >= 1 AND Rating <= 5.
Q4
B — A valid range needs both comparisons to be true, so they must be joined with AND. With OR, every age passes (for example 5 is <= 16 and 50 is >= 11). It should be IF Age >= 11 AND Age <= 16.
Q5
D — The loop should repeat until the mark is inside the range, which needs both tests true, so AND. With OR the condition is always true and invalid marks are accepted. It should be UNTIL Mark >= 0 AND Mark <= 10.