GCSE · Computer Science · AQA · Spec 8525

Keyboard input

When a program asks you a question, it's doing something simple but powerful: it stops, waits for your answer, and keeps what you typed to use later.

Computer Science · Algorithms

Trace table — dry run the code

Aisha runs this little quiz. Step through it and watch what happens at each USERINPUT line: the program freezes until she types.

1OUTPUT "What is your name?"
2name ← USERINPUT
3OUTPUT "Hi " + name + "!"
4OUTPUT "Closest planet to the Sun?"
5answer ← USERINPUT
6IF answer = "Mercury" THEN
7 OUTPUT "Correct, " + name + "!"
8ELSE
9 OUTPUT "Nearly, " + name + ". It's Mercury."
10ENDIF
name
answer
Output
Press Start to run the first line.
·

Ready when you are — step through one line at a time.

Predict, then check

Two users, one program.

A program has three lines: OUTPUT "Favourite food?", then food ← USERINPUT, then OUTPUT "Mmm, " + food + "!". Sam runs it and types pizza, and the screen ends with Mmm, pizza! Then Jo runs exactly the same program and types sushi. What does Jo's last line say?

Spot the bug

Where did the pet's name go?

Kai wants a program that asks for a pet's name and then says hello to the pet. When it runs, the program waits and the user types Biscuit, but the greeting never says Biscuit. Which line goes wrong?

Kai's program — which line goes wrong?

Your turn

Build a program that asks and replies

Write a program that asks for the user's name and favourite colour, then replies using both. Choose each missing line.

  1. OUTPUT "What is your name?"
  2. missing step
Which line is step 2?

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

How a program stops, waits for you, and keeps what you typed

What you need to know

  • An input line makes the program pause until the user types something and presses Enter.
  • The typed value is stored in a variable: name ← USERINPUT stores it in name. (In Python the same idea is written name = input().)
  • Later lines use the typed value by naming the variable, and it stays there until the program changes it.
  • The programmer writes the input line, but the user supplies the value each time the program runs.
  • Show a prompt with an OUTPUT line before the input, so the user knows what to type.

The big picture

Keyboard input lets a program get a value from the user while it is running. When the program reaches an input line, it stops and waits until the user types something and presses Enter. What they typed is stored in a variable, and any later line can use it by naming that variable. Because the value comes from the user rather than from the code, the same program can behave differently for different people.

Key points

1Input means pause, then store.
2The value is typed while the program runs; it is not written in the code.
3Prompt first, then input, then use.
4An input that isn't stored in a variable is lost.

Worked example

Problem

A program runs these three lines: OUTPUT "Which town do you live in?", then town ← USERINPUT, then OUTPUT "I hear " + town + " is lovely." The user types Leeds. What does the program output, in order?

⚠ Watch out

Thinking the input line shows something, or that the programmer decides its value. OUTPUT shows; USERINPUT collects. The value in town ← USERINPUT isn't known until someone types it.

🧠

Memory hook

Pause, store, use. Picture a waiter: they stop at your table and wait, write your order on their pad (the variable), and the kitchen cooks from the pad. The order comes from you, not from whoever printed the menu.

✓

Check yourself

Without looking back: a program contains the line colour ← USERINPUT. What happens when the program reaches this line, and how can a later line use what the user typed?

Flashcards

(7)
What does a program do when it reaches an input line?
It pauses and waits until the user types something and presses Enter.
In city ← USERINPUT, where does the typed value go?
Into the variable city, where later lines can use it.
How does a later line use what the user typed?
By naming the variable: OUTPUT "Hello " + name shows whatever is stored in name.
Who decides the value stored by name ← USERINPUT?
The user, while the program runs. The programmer only writes the line.
Why put an OUTPUT prompt before an input line?
So the user knows the program is waiting and what they should type.
What happens to typed input that isn't stored in a variable?
It is lost, so no later line can use it.
Why do programs take input at all?
So the same code can work with different values on each run: different users, different results.

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 AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)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 30 September 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.