GCSE · Computer Science · Edexcel · Spec 1CP2
Validation – presence check
Press Enter without typing a thing. Does the program crash, complain, or just carry on? The answer is a bit surprising, and it is the whole reason this topic exists.
Computer Science · Validation
Step through the presence check
The user presses Enter, presses Enter again, then types a name. Press Next and watch what name holds each time.
At every step, ask yourself: what is name holding right now?
1 name = input("What is your name? ")2 while name == "":3 print("Please enter something.")4 name = input("What is your name? ")5 print("Hello, " + name)
Variables
Output
What is your name?
Step 1: The question appears and the user just presses Enter. So name holds an empty string: a real value with nothing in it.
Use Next to step one line at a time.
Predict: no check at all
Here is the same name program with the loop taken out. Commit to a prediction first.
name = input("What is your name? ") print("Hello, " + name) The user presses Enter without typing anything. What does this program do?
Computer Science · Validation
Which check does each situation need?
Sort each situation into the check that suits it.
Still to sort
Empty string (presence) check (0)
Makes sure the user has entered something.
Where the line is: It asks only whether anything was entered, not how much or how big.
Minimum length check (0)
Makes sure the input has at least a set number of characters.
Where the line is: It counts characters, so it suits text that must be long enough.
Range check (0)
Confirms numerical input falls within a set range.
Where the line is: It is about numbers lying between limits, not about how many characters were typed.
Three checks can help make code more robust. Pick a situation, then pick the check that suits it.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
The program that says hello to nobody, and the loop that won't let it.
What you need to know
- Validation means checking data against a set of criteria before the program uses it, to make sure it is acceptable.
- Press Enter without typing and the program receives an empty string. It still runs, leaving the data blank.
Have a goMo says: "Press Enter on nothing and the variable doesn't even exist, it's just missing." Is Mo right about what the program receives?
No. The program receives an empty string, which is a real value.
Empty is not the same as missing. The input is an empty string, and the program still runs with the data left blank.
- An empty string check makes sure the user has entered something. That check is called the presence check.
- Build it with a while loop: while the input is an empty string, show a message and ask again.
Have a goA pupil writes while name != "": as their presence check. What goes wrong when the user just presses Enter?
The loop is skipped, so the program carries on with the name left blank.
The loop must run while the input IS an empty string. Testing for not-empty asks again when something was typed and does nothing when it wasn't.
- The loop keeps repeating until the user types something in. After that, the program continues, for example by greeting them.
Have a goA user presses Enter three times, then types Ali. How many times does "Please enter something." appear?
Three times.
The condition is true after each empty entry, so each one shows the message. Typing Ali makes it false and the loop ends.
- Second pattern: a while True loop repeats the question, an if statement tests the input, and break ends the loop.
- A presence check makes code more robust and improves the user experience by guiding users to give valid data.
- Without validation programmed in, the program runs with invalid data and may crash.
- Three validation checks can make code more robust: an empty string check, a minimum length check, and a range check.
The big picture
Pressing Enter without typing gives a program an empty string, and without a check it just carries on with the data left blank. A presence check (an empty string check) fixes that with a loop that keeps asking until something has been entered. It makes code more robust and the experience better for the user, and it is one of three validation checks alongside the minimum length check and the range check.
Key points
Worked example
Problem
Write the lines that ask for a favourite colour and will not carry on until the user has typed something.
⚠ Watch out
Thinking that an empty entry crashes the program or sets off an error by itself. It does not. The program receives an empty string and carries on with the data blank, so the check has to be programmed in.
Memory hook
Enter on nothing is still something: an empty string. No check, no stop.
Check yourself
Cover the page and write the loop for a presence check on a variable called name. Then say, in one sentence, when the loop stops and what the program does next.
Flashcards
(12)What is validation?
What does the program receive if the user presses Enter without typing?
What is the presence check?
How is a presence check built with a while loop?
What happens once the user types something into a presence check loop?
In the while True pattern, what do while True, if and break each do?
Why does a presence check make code more robust?
How does a presence check improve the user experience?
What can happen if no validation is programmed in?
Name the three validation checks.
What does a range check confirm?
Does passing a presence check prove the data is right?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
- Programming arithmetic operators
- Programming logical operators
- Programming relational operators
- Reading, writing, analysing and refining programs
- Single entry/exit code blocks
- String manipulation
- Structural components of programs
- Structured data types
- User input handling
- Validation – length check
- Validation – range check
- Variables and constants in programs
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 21 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.