Type checking in code
A check that input is the expected data type, using .isdigit(), try/except around int() or float(), or isinstance(). input() is always text, so check before converting.
Understanding Type checking in code in VCE Software Development U3O1
What it does: If int() cannot convert the text it raises a ValueError, and the except block handles it. This is a type check using try/except. float() accepts values like 1.75 that isdigit() would reject, so try/except around float() checks for a decimal number. input() always returns text, even when the user types digits. That is why we check the value before converting it. isdigit() is a string method, so it is called with dot notation on the string: age.isdigit(). isinstance() checks the actual data type of a value against a type such as float, int or str.
Common mistakes: isdigit is a method, so it needs brackets to be called. Without them the condition is just the method object, which is always True, so nothing is checked. It should be if age.isdigit():. input() always returns a string, so isinstance(num, int) is always False. To check that the text is a whole number, use num.isdigit().
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 114–124) and word search (Modules 114–141).
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
type checkFill in the Blanks
Spot the Error
Student with a class code? Join your class →