GCSE · Computer Science · Eduqas · Spec C500QS

Variables, operators, inputs, outputs and assignment

score = score + 1 looks impossible. So why does every game you've ever played rely on it?

Computer Science · Variables in Python

Be the computer: what is in the box now?

A user types -17. Call what each variable holds before the table shows it.

Step through the program. At each marked line, make your call first. Nothing is run here: every value is the lesson's, checked against Python.

score = 0
score = 10
score = score + 1
answer = input("Whole number? ")
n = int(answer)
q = n // 5
r = n % 5
p = 2 ** 3
neg = n < 0
print(neg)
scoreanswernqrpneg
0

Step 1. score is created and given its first value, 0. This first row is worked for you.

Step 1 of 10Called right: 0 of 6

Ask yourself: what is in each box right now, and what did this line put in it?

Computer Science · The = trap

What does this line actually do?

A classmate stares at one line of Python and frowns: score = score + 1

Which is closest to what you think this line means?
How sure are you?

Computer Science · Data types

What kind of data is it?

Pick a value, then pick the data type it belongs to.

Still to sort

Integer (0)

A whole number

Where the line is: No decimal point and no speech marks. Add a decimal point and it becomes real; add speech marks and it becomes a string.

Real (float) (0)

A decimal number

Where the line is: Real numbers have a fractional part, even when it is a trailing .0.

Boolean (0)

True or false

Where the line is: Only two possible values: True and False.

String (0)

Text, which can include numbers and symbols

Where the line is: Anything in speech marks is text, even if the characters are digits. A string can be longer than one character.

Character (0)

A single character

Where the line is: One character only. More than one and it is a string.

7 of 7 still to sort.

Computer Science · Run it and read it

Read what Python says

This program should ask for two whole numbers and print their total. A tester types 1, then 2. Press Run, read what happens, then choose how to fix the flagged line.

Python
  1. first = input("First number: ")
  2. print("Adding...")
  3. print(first + second)

The messages and outputs are what Python 3 gives for this exact code; other versions or languages may word them differently.

Computer Science · Variable or constant?

Which properties fit which?

Tick every property that fits each item, then check your grid.

A variable
A constant declared in Visual Basic or C#
A Python name in CAPITALS

Exam-style question

Make it easier to maintain

A programmer's Python program works out the price of items. It uses the variable names a and b, and the number 0.2 for a tax rate is typed directly into six different lines. Explain two ways the programmer could make the program easier to maintain. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: Say what the programmer does, then say what benefit it brings. One mark for each.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Trace a Python program line by line and always know what is in each box.

What you need to know

  • A variable is a named place in memory. It holds one value at a time, and that value can change.
  • Assignment stores a value: age = 22. Assign again and the old value is overwritten, so only the last value is kept.
  • Have a goA classmate says: "x = 5 and then x = 9 means x is 5 and 9 at the same time." What does x really hold, and what happened to the 5?

    x holds 9. The 5 was overwritten and is gone.

    A variable holds one value at a time, so a new assignment replaces the old value rather than sitting beside it.

  • The right side of = is worked out first, then stored in the variable on the left, so score = score + 1 adds one.
  • Input is data sent to a program to be processed; output is information produced by that processing. Neither is automatic: the programmer codes where and how.
  • In Python, input() takes what the user types and print() displays it, but input() always returns a string, so cast with int() or float().
  • Have a goage = input() and the user types 8. Which word from today tells you what age holds, and which function would you wrap round input() to get a whole number?

    A string (the text "8"); int().

    input() always returns a string, even for digits, so you must cast it before treating it as a number.

  • A data type is the kind of data: integer, real, Boolean, string or character. Speech marks make digits a string.
  • Arithmetic operators are +, -, * and /, plus ** for powers. In Python, / always gives a real (float) result.
  • // rounds the quotient down and % gives the matching remainder: 17 // 5 = 3 and 17 % 5 = 2.
  • Have a goUsing the idea that // rounds down and % gives the remainder, what are 20 // 6 and 20 % 6?

    3 and 2.

    6 fits into 20 three whole times (18), and 20 - 18 leaves 2. The whole-number part and the remainder fit together.

  • Relational operators (==, !=, <, >, <=, >=) compare two values and give True or False. = stores, == tests.
  • Use meaningful lowercase_with_underscore names; a constant should not change, and Python marks one only with CAPITALS.

The big picture

A variable is a named memory location holding one value at a time. Assignment works out the right side first, then overwrites the left. input() returns a string, so you cast it with int() or float(). Operators do arithmetic (including // and %) or compare values to give True or False, and = stores while == tests.

Key points

1A variable holds one value at a time; assigning again overwrites it.
2Right side first, then store on the left: that is how score = score + 1 works.
3input() always returns a string; cast with int(), float() or str().
4// is floor division and % is the matching remainder; == tests and = stores.
5A Python name in CAPITALS is a constant by convention only.

Worked example

Problem

A school trip has 23 students and each minibus seats 8. Write Python that stores how many minibuses will be full and how many students are left over, then say what each variable holds.

⚠ Watch out

Reading = as 'is equal to' from maths. In Python, = stores the result of the right-hand side in the variable on the left, and == is the symbol that tests whether two values are equal.

🧠

Memory hook

Right side first, then post it to the box on the left, and the old value is thrown out.

✓

Check yourself

A variable called age holds 16. Which symbol would you use to test whether age is 16, which one would you use to change it to 17, and why can't you swap them?

Flashcards

(15)
What is a variable?
A named piece of data stored in memory that holds one value at a time. The value can change while the program runs.
What happens to the old value when you assign a new one?
It is overwritten. The variable holds the last value assigned to it.
In which order does an assignment run?
The expression on the right of = is evaluated first. The result is then stored in the variable named on the left.
Do input and output happen automatically?
No. The programmer must specify in the code exactly where and how input and output are handled.
What type does Python's input() return?
A string, even if the user types a number.
Name the three Python casting functions.
str() converts to a string, int() to an integer, float() to a real (floating point) number.
List the five common data types.
Integer, real/floating point, Boolean, string and character.
Declaration or initialisation: which does Python use?
Initialisation only. Declaration states a name and data type; initialisation gives a starting value.
What causes a NameError?
Using a variable before it has been initialised.
How does a constant differ from a variable?
Both hold a value in a memory location, but a constant's value is fixed for the whole run of the program.
Does a CAPITALS name make a Python value unchangeable?
No. Python has no constants. CAPITALS is only a convention, so the value is not immutable.
What do // and % give for -17 and 5?
-17 // 5 is -4 (rounded down, not -3) and -17 % 5 is 3.
What does a relational operator return?
A Boolean result, True or False.
What is the difference between = and ==?
= stores a value in a variable. == tests whether two values are equal. They must not be confused.
What are the Python naming conventions for variables?
Use meaningful names, in lowercase with an underscore separating words, such as first_name.

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

See the full Eduqas Computer Science curriculum →

How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 15 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.