← VCE Software Development U3O1

Existence checking in code

An existence check tests that a value was actually entered. strip() removes spaces, so this is True for empty or space-only input, and an error message can be shown.

Understanding Existence checking in code in VCE Software Development U3O1

What it does: The existence check detects the missing data and the print() line tells the user what is wrong. Calling strip() on the input turns ' ' into an empty string, so a later comparison with '' will catch it. A comparison needs == (two equals signs). A single = is assignment and causes a syntax error. The error message belongs in the branch where the value IS empty. Using != would show it when data is present. The existence check needs the comparison operator == to test whether the stripped value is empty.

Common mistakes: This branch runs when the name is empty, so it should show a missing-data message such as print('Name is required'), not a welcome that uses the empty value. The else keyword must be followed by a colon. It should be else:.

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 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.

Learning
Duo
Which condition correctly checks that a user typed nothing into a field?
if value.strip() == '':if value.strip() = '':
Matches
if value == '': print('Missing') # user types three spaces
↓
Without strip(), a space-only input is not equal to '', so the existence check wrongly passes. Use value.strip() == ''.
Applying
Meanings
Term
if value.strip() == '':
Meaning
An existence check tests that a value was actually entered. strip() removes spaces, so this is True for empty or space-only input, and an error message can be shown.
Practice
name = input("Enter your name: ")
Testing
Gaps
if value.() == '':
Check Answer
Spots
2if name.strip() == '':
3 print('Welcome', name)

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

The 'Seal' badge — Smooth Formatter, 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 that a user typed nothing into a field?
A. if value.strip() = '':
B. if value.strip() == '': ✓
A comparison needs == (two equals signs). A single = is assignment and causes a syntax error.
2. A user types three spaces and presses Enter. Which check catches this as missing data?
A. if value.strip() == '': ✓
B. if value == '':
' ' is not equal to '', so the second check misses it. strip() removes the spaces first, leaving an empty string.
3. True or false: an existence check tests whether the value is sensible, such as an age between 0 and 120.
A. False - it only tests that something was entered ✓
B. True - it tests that the value is sensible
Checking that a value is sensible is a range check. An existence check only confirms that data is present.
4. Which code shows a message when the name field is missing?
A. if name.strip() != '': print('Please enter a name')
B. if name.strip() == '': print('Please enter a name') ✓
The error message belongs in the branch where the value IS empty. Using != would show it when data is present.
5. How can you check that a list has at least one item before using it?
A. if len(scores) == 0: ✓
B. if scores.strip() == '':
strip() is a string method, so it fails on a list. Use len() and compare it to 0 to test whether a list is empty.

Match the Pairs

if value.strip() == '': → Existence check: True when the input is empty or only spaces, so nothing real was entered
if len(items) == 0: → Existence check on a list: True when the list holds no items, so there is no data to use
Show an error message when a required field is left blank → if name.strip() == '': print('Name is required')
Stop space-only input from passing an existence check by removing the spaces first → text = input('Enter: ').strip()
if value == '': print('Missing') # user types three spaces → Without strip(), a space-only input is not equal to '', so the existence check wrongly passes. Use value.strip() == ''.
if value.strip() = '': → A single = is assignment and causes a syntax error. A comparison needs ==, as in value.strip() == ''.

Key Term

if value.strip() == '':
An existence check tests that a value was actually entered. strip() removes spaces, so this is True for empty or space-only input, and an error message can be shown.

Fill in the Blanks

1. value = input("Enter your name: ") if value.strip() == '': print("Please enter a value")
Hint: Type the string method that removes spaces from both ends of the text.
2. name = input("Name: ") if name.strip() == '': print("Name is required")
Hint: Type the comparison operator that tests whether two values are equal.
3. scores = [] if len(scores) == 0: print("No scores entered")
Hint: Type the built-in function that counts how many items are in a list.
4. city = input("City: ") if city.strip() == '': print("City is missing")
Hint: Type the function that shows a message to the user when data is missing.
5. import os if not os.path.exists("data.csv"): print("File not found")
Hint: Type the os.path function that checks whether a file is present.

Spot the Error

Question 1
A name = input('Name: ')
B if name.strip() == '':
C print('Welcome', name)
D else:
E print('Hello', name)
Line C — This branch runs when the name is empty, so it should show a missing-data message such as print('Name is required'), not a welcome that uses the empty value.
Question 2
A email = input('Email: ')
B if email.strip() == '':
C print('Email is required')
D else
E print('Saved')
Line D — The else keyword must be followed by a colon. It should be else:.
Question 3
A age = input('Age: ')
B while age.strip() == '':
C print('Age is required')
D age = age.strip()
E print('Thanks')
Line D — The loop never asks again, so age stays empty and the loop runs forever. The line should ask again with age = input('Age: ').
Question 4
A city = input('City: ')
B if city.strip() = '':
C print('City is required')
D else:
E print(city)
Line B — A single = is assignment, not comparison. The existence check needs == to compare with the empty string.
Question 5
A code = print('Code: ')
B if code.strip() == '':
C print('Code missing')
Line A — print() only displays text and does not read what the user types. The value must be read with input('Code: ').

Student with a class code? Join your class →