← IGCSE Computer Science Paper 2

Error: wrong logical operator

Use OR, not AND, to catch an invalid mark. A mark cannot be below 0 and above 100 at once, so AND is never TRUE. OR is TRUE when either part is TRUE.

Understanding Error: wrong logical operator in IGCSE Computer Science Paper 2

What it does: 120 is above 100, but it is not below 0. AND needs both parts TRUE, so the condition is FALSE even though the mark is invalid. Only the logical operator is wrong. Replacing AND with OR means either out-of-range test can make the condition TRUE.

Common mistakes: A mark cannot be below 0 and above 100 at the same time, so AND is never TRUE and invalid marks are never caught. It should be IF Mark < 0 OR Mark > 100. AND needs both parts to be TRUE, which is impossible for one mark. A mark of 150 or -5 would slip through. Use OR so that either part being TRUE catches the invalid mark.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 232–241) and word search (Modules 232–253).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which condition correctly checks for an invalid mark (outside 0 to 100)?
Mark < 0 AND Mark > 100Mark < 0 OR Mark > 100
Matches
IF Mark < 0 AND Mark > 100 THEN OUTPUT "Invalid mark" ENDIF
↓
Wrong logical operator: AND is used where OR is needed, so the condition is never TRUE and no invalid mark is ever reported. Fix: use OR.
Applying
Meanings
Term
Mark < 0 OR Mark > 100
Meaning
Use OR, not AND, to catch an invalid mark. A mark cannot be below 0 and above 100 at once, so AND is never TRUE. OR is TRUE when either part is TRUE.
Practice
IF Mark < 0 OR Mark > 100
Testing
Gaps
IF Mark < 0 Mark > 100 THEN
Check Answer
Spots
2INPUT Mark
3IF Mark < 0 AND Mark > 100

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Kangaroo Rat' badge — Speed Typer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which condition correctly checks for an invalid mark (outside 0 to 100)?
A. Mark < 0 OR Mark > 100 ✓
B. Mark < 0 AND Mark > 100
A mark cannot be below 0 and above 100 at the same time, so AND is never TRUE. OR is TRUE when either part is TRUE.
2. Mark < 0 AND Mark > 100 is used to catch invalid marks. What is the problem?
A. It is never TRUE, so no invalid mark is caught ✓
B. It is always TRUE, so every mark is rejected
No number is both less than 0 and greater than 100, so the condition is always FALSE. Invalid marks slip through.
3. Mark ← 150. What does Mark < 0 AND Mark > 100 evaluate to?
A. FALSE ✓
B. TRUE
150 > 100 is TRUE but 150 < 0 is FALSE. AND needs both parts TRUE, so the result is FALSE even though 150 is invalid.
4. Mark ← 150. What does Mark < 0 OR Mark > 100 evaluate to?
A. FALSE
B. TRUE ✓
Mark > 100 is TRUE. OR is TRUE when either part is TRUE, so the invalid mark is caught.
5. You test Mark < 0 OR Mark > 100 with the valid value 50. What result should you get?
A. TRUE
B. FALSE ✓
50 < 0 is FALSE and 50 > 100 is FALSE. Both parts are FALSE, so OR gives FALSE. A valid mark is not flagged as invalid.

Match the Pairs

IF Mark < 0 AND Mark > 100 THEN → Faulty condition: no mark is below 0 and above 100 at the same time, so it is never TRUE and invalid marks are missed.
IF Mark < 0 OR Mark > 100 THEN → Correct condition: TRUE for an invalid mark, because OR is TRUE when either part is TRUE.
Testing the faulty condition with an invalid value of 120 still gives FALSE, which shows the logic is wrong. → Mark ← 120 IF Mark < 0 AND Mark > 100 THEN
To correct the error, change AND to OR so that either invalid case triggers the message. → IF Mark < 0 OR Mark > 100 THEN OUTPUT "Invalid mark" ENDIF
IF Mark < 0 AND Mark > 100 THEN OUTPUT "Invalid mark" ENDIF → Wrong logical operator: AND is used where OR is needed, so the condition is never TRUE and no invalid mark is ever reported. Fix: use OR.
IF Mark >= 0 OR Mark <= 100 THEN OUTPUT "Valid mark" ENDIF → Wrong logical operator: OR is used where AND is needed, so every number counts as valid, even -5 or 120. Fix: use AND.

Key Term

Mark < 0 OR Mark > 100
Use OR, not AND, to catch an invalid mark. A mark cannot be below 0 and above 100 at once, so AND is never TRUE. OR is TRUE when either part is TRUE.

Fill in the Blanks

1. IF Mark < 0 OR Mark > 100 THEN
Hint: Type the logical operator that is TRUE when either part is TRUE, so an invalid mark is caught.
2. IF Mark >= 0 AND Mark <= 100 THEN OUTPUT "Valid" ENDIF
Hint: Type the logical operator that needs both parts TRUE, which is correct for a valid range.
3. WHILE Mark < 0 OR Mark > 100 DO INPUT Mark ENDWHILE
Hint: Type the logical operator that repeats the input when the mark is below the range or above the range.
4. Mark ← 120 OUTPUT Mark < 0 OR Mark > 100 // Output: TRUE
Hint: Type the Boolean value shown when only one part of the OR condition is TRUE for the invalid value 120.
5. IF Mark < 0 OR Mark > 100 THEN OUTPUT "Invalid mark" ENDIF
Hint: Type the relational operator that tests whether the mark is above the upper limit.

Spot the Error

Question 1
A OUTPUT "Enter a mark"
B INPUT Mark
C IF Mark < 0 AND Mark > 100
D THEN
E OUTPUT "Invalid mark"
F ENDIF
Line C — A mark cannot be below 0 and above 100 at the same time, so AND is never TRUE and invalid marks are never caught. It should be IF Mark < 0 OR Mark > 100.
Question 2
A IF Mark < 0 AND Mark > 100
B THEN
C OUTPUT "Invalid mark"
D ENDIF
Line A — AND needs both parts to be TRUE, which is impossible for one mark. A mark of 150 or -5 would slip through. Use OR so that either part being TRUE catches the invalid mark.
Question 3
A INPUT Mark
B Valid ← TRUE
C // check the mark
D IF Mark < 0 AND Mark > 100
E THEN Valid ← FALSE
F ENDIF
Line D — With AND the condition is never TRUE, so Valid stays TRUE even for a mark such as 120. It should be OR so that either an out-of-range low or high mark sets Valid to FALSE.
Question 4
A Mark ← 150
B IF Mark < 0 AND Mark > 100
C THEN OUTPUT "Invalid"
D ENDIF
Line B — Testing with the invalid value 150 shows the fault: 150 > 100 is TRUE but 150 < 0 is FALSE, so AND gives FALSE and nothing is output. Changing AND to OR makes the program output Invalid.
Question 5
A Bad ← Mark < 0 AND Mark > 100
B IF Bad = TRUE
C THEN OUTPUT "Invalid"
D ENDIF
Line A — Bad should be TRUE when the mark is below 0 or above 100. With AND it is always FALSE, because no mark can be both. It should be OR.

Student with a class code? Join your class →