KS3 · Computer Science

Python: output, input and variables

Type Lucas into a program that says Hello Aisha and it still says Hello Aisha. Let's find out why, and how to make it listen.

Computer Science · Algorithms

Trace table — dry run the code

One tiny program, run twice. Step through it and follow the name: in through the keyboard, held in user, out onto the screen.

1print("What is your name?")
2user = input()
3print(f"Hello {user}")
run
keyboard
user
Output
Press Start to run the first line.
·

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

Predict, then check

Here is a program that looks like it greets whoever runs it. Does it?

A program prints the question "What is your name?", stores the answer with user = input(), then runs print("Hello Aisha"). Lucas sits down and types Lucas. What does the last line put on the screen?

Two ways to get the name into the text

print(f"Hello {user}")vsprint("Hello " + user)

Both lines put the name the user typed into the message. Look at how each one does it.

Focus

How the value gets in

print(f"Hello {user}")

Curly brackets mark the spot, and Python fills it with whatever user holds.

print("Hello " + user)

The + operator joins the text on to the variable.

The insight

In an f-string the curly brackets are the "put the value here" marker. Leave them out and the value never goes in.

What sits inside the speech marks

print(f"Hello {user}")

All of it: Hello {user}, with an f just before the opening speech mark.

print("Hello " + user)

Only the text, "Hello ". The variable user sits outside the speech marks.

Reading it back

print(f"Hello {user}")

Easier to read and more straightforward.

print("Hello " + user)

Harder to read, because the text and the variable are split up.

Computer Science · Python

Now you write one: two questions, two variables

Write a program that asks for a favourite colour and a favourite animal, stores each answer, then prints a sentence such as I love red cats!

  1. print("What is your favourite colour?")
  2. missing step
Which line is step 2?

Computer Science · Python

What happens when each line runs?

Pick a line, then pick what happens when it runs.

Still to sort

Syntax error (0)

A rule of Python's syntax is broken.

Where the line is: A missing closing bracket or a missing speech mark.

Stops with a different error (0)

An error message, but not a syntax error.

Where the line is: Python expects print in lowercase.

Runs but prints the wrong thing (0)

No error message, just not what you meant.

Where the line is: Nothing breaks, so Python has nothing to complain about.

Runs as intended (0)

Prints the name the user typed.

6 of 6 still to sort.

Every programming language has rules for syntax, and a program has to follow them so the language can understand it. But breaking a rule is only one way for a line to go wrong. Sort each line by what actually happens. Assume user already holds a name.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

What you need to know

  • Input is data sent into a program to be processed, and output is information the computer gives back out.
  • A keyboard is a common input device, and text or error messages on the screen are output.
  • Python runs code line by line, top to bottom, unless something changes the order.
  • Have a goA program has three lines, from top to bottom: print("B"), print("A"), print("C"). What does the screen show, in order?

    B, then A, then C.

    Python follows the order of the instructions, top to bottom, not alphabetical order, unless something changes the order.

  • print() sends text to the screen: lowercase print, then brackets, with the text inside speech marks.
  • Have a goDev types Print("Hi") with a capital P and says, "Python won't care about a capital letter." What do you tell Dev?

    Python does care: print has to be lowercase, so Dev's line gives an error.

    It feels like capitals are just decoration, but in Python the word print is written in lowercase.

  • A string is a piece of text in speech marks, and it can hold words, numbers and symbols.
  • input() takes what the user types, and you store it in a variable, like user = input().
  • If print has a fixed name typed into it, it prints that name whatever the user enters. Use the variable holding the input.
  • An f-string puts a variable's value into text using curly brackets: print(f"Hello {user}").
  • Have a goFill the gap so the line shows whatever name the user typed, which is held in user: print(f"Hello ___")

    {user}

    The curly brackets mark where the value goes, so the variable name sits inside them.

  • You can store more than one input, each in its own variable, and use them all in one f-string.
  • Every programming language has syntax rules, and a missing closing bracket or speech mark breaks them: a syntax error.

The big picture

Input gets data into a program and output gets information out. In Python, input() takes what the user types and stores it in a variable, and print() with an f-string can put it back on the screen, so the same code gives different output for different users. You will also learn to tell a syntax error from a line that runs but prints the wrong thing.

Key points

1input() takes what the user types, and a variable holds it.
2print() only shows the user's input if it uses the variable that holds it.
3In an f-string, curly brackets mark where a variable's value goes.
4Python runs the lines in order, so output appears in the same order as the instructions.

⚠ Watch out

Typing a name straight into the print line, like print("Hello Aisha"), and expecting it to greet whoever runs the program. It always prints that fixed name. The print statement has to use the variable that holds the input.

🧠

Memory hook

In through the keyboard, held in the variable, out through the curly brackets.

✓

Check yourself

A program stores a typed answer in snack, then runs print(f"Yum, {snack}!"). Someone types toast. What appears, and what would appear without the curly brackets?

Flashcards

(14)
What is input?
Data that is sent to a program to be processed. It gets data into the computer.
What is output?
Information produced by a computer system as a result of processing data. It gets information out.
Which device is a common way to give a Python program input?
The keyboard. It is used to write Python code and to type input when a program runs.
In what order does Python run the lines of a program?
Line by line from top to bottom, unless something changes the order, like repeating steps or making decisions. So output appears in the same order as the instructions.
How do you write the print function correctly?
print in lowercase, then brackets, with the text inside speech marks: print("Hello world").
What is a string?
A piece of text inside quotation or speech marks. It can contain words, numbers and symbols.
What does user = input() do?
input() takes what the user types, and the value entered is stored in the variable user.
Why does print("Hello Aisha") say Hello Aisha even when Lucas types his name?
The name is typed into the print statement, so it always prints that name. To output what the user enters, print must use the variable that holds the input.
What do the curly brackets do in print(f"Hello {user}")?
They mark where the value of the variable goes. Whatever the user entered is joined next to the word Hello.
f-string or + : which is easier to read?
The f-string, print(f"Hello {user}"). It is easier to read and more straightforward than joining text with +, as in print("Hello " + user).
How do you store two different inputs?
Each input goes in its own variable, like colour and animal, and an f-string can combine them: I love red cats!
Which two slips in a print line are syntax errors?
A missing closing bracket and a missing speech mark. All programming languages have syntax rules that a program must follow.
What happens if you write Print with a capital P?
It is an error, because print must be lowercase in Python. It is a different kind of error from a syntax error.
What happens if you leave out the curly brackets in an f-string?
The variable's value is not inserted. The program runs, but prints the variable's name as text instead of the value.

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 KS3 Computer Science topics

See the full KS3 Computer Science curriculum →

How this lesson was checked. This KS3 Computer Sciencelesson 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 8 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.

Helpful guides for parents and students