Existence checking in Python
An existence check tests that the user actually entered something, so the input is not an empty string. len(name) > 0 does the same job. Loop and re-ask until it passes.
Understanding Existence checking in Python in VCE Data Analytics U4O1
What it does: Pressing Enter gives input() an empty string (""). Testing name == "" catches this case so an error message can be shown. The while loop keeps running as long as name is empty. Each pass asks again, so the loop only ends once the user types something. Checking for a whole number is a type check. An existence check only tests that the input is not empty. An if statement needs a colon at the end of the line. Without it Python gives a SyntaxError. A good error message tells the user what went wrong. Here the problem is that nothing was entered, not that a number was out of range.
Common mistakes: == compares instead of assigning, so name never changes and the loop never ends. It should be name = input("Name: ") to re-ask and store the new answer. The check is reversed. This greets the user only when nothing was entered. An existence check should use != "" so the greeting runs only when something was entered.
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 name != ""Fill in the Blanks
Spot the Error
Student with a class code? Join your class →