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

name=""

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.

1 / 9

Use Next to step one line at a time.

Step 1 of 9: The question appears and the user just presses Enter. So name holds an empty string: a real value with nothing in it..

Exam line: A presence check is a loop that keeps asking while the input is an empty string. The program only continues once something has been typed.
Watch out: Pressing Enter without typing still gives the program a value: an empty string. It is the loop's condition that notices it.

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

Finish the while True check

This version of the presence check uses while True. It should keep asking until the user types something, then say hello. Choose the two missing lines.

  1. while True:True never becomes False, so this loop repeats until something inside it ends it.
  2. name = input("What is your name? ")The question is asked inside the loop, so it is asked again on every pass.
  3. missing step
Which line is step 3?

Exam line: while True keeps asking, if tests the input, and break leaves the loop once the input is valid.

Computer Science · Validation

What does a presence check promise?

A name program now has a presence check. The user types the letters xyz and presses Enter, so the check passes.

Which is closest to what you think a presence check tells you?
How sure are you?

Exam line: A presence check shows something has been entered. Say that, not that the data is correct.

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.

6 of 6 still to sort.

Three checks can help make code more robust. Pick a situation, then pick the check that suits it.

Exam line: Match the check to what must be true of the input: something entered, enough characters, or a number within a set range.
Watch out: A range check is for numerical input. It confirms the number falls within a set range.

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

1Validation checks data against criteria before the program uses it.
2Pressing Enter without typing gives an empty string, and the program still runs with the data blank.
3A presence check is an empty string check, built as a loop that asks again until something is entered.
4There are three checks: empty string, minimum length and range.

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?
Checking data against a set of criteria before the program uses it, to make sure it is acceptable.
What does the program receive if the user presses Enter without typing?
An empty string, which is a value with nothing in it. The program still runs, leaving the data blank.
What is the presence check?
The empty string check: it makes sure the user has entered something.
How is a presence check built with a while loop?
While the input is an empty string, show a message and ask again. The loop repeats until something is typed.
What happens once the user types something into a presence check loop?
The condition becomes False, the loop ends and the program continues.
In the while True pattern, what do while True, if and break each do?
while True repeats the question, if tests the input, and break ends the loop once the input is valid.
Why does a presence check make code more robust?
It stops the program continuing with missing input.
How does a presence check improve the user experience?
It guides the user to provide valid data.
What can happen if no validation is programmed in?
The program runs with invalid data and may crash.
Name the three validation checks.
An empty string check, a minimum length check and a range check.
What does a range check confirm?
That numerical input falls within a set range.
Does passing a presence check prove the data is right?
No. Validation checks data is acceptable against criteria. A presence check only shows something was entered.

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 posted

More Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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.