Range checking in Python
A range check tests that a number lies between a minimum and maximum. This chained comparison is True only when mark is from 0 to 100 inclusive, so the boundary values 0 and 100 are accepted.
Understanding Range checking in Python in VCE Data Analytics U4O1
What it does: Using <= includes the boundary values, so a mark of exactly 0 or exactly 100 is valid. Using < would wrongly reject them. When the range check fails, the else branch runs and tells the user why the input was rejected and what range is allowed. A range check puts the minimum on the left and the maximum on the right: 0 <= mark <= 100. Reversing the operators means no number can pass. Python lets you chain comparisons, so one condition tests both the minimum and the maximum. Many other languages need two separate tests joined with 'and'. 101 is above the maximum of 100, so the condition is False. The else branch should print an error message such as 'Mark must be between 0 and 100'.
Common mistakes: The if statement is missing its colon at the end. It should be: if 0 <= mark <= 100:. Using < 100 rejects the boundary value 100, which is a valid score. The upper check should be <= 100 so that 100 is accepted.
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 63–83) and word search (Modules 63–105).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
if 0 <= mark <= 100:Fill in the Blanks
Spot the Error
Student with a class code? Join your class →