Programming Concepts

beginner20 min

Learning objectives

  • Declare and initialise variables and constants
  • Use assignment statements correctly
  • Write sequential programs
  • Apply meaningful naming conventions
  • Recognise where selection, iteration, procedures and functions will be used later in the course

Learn

AQA 4.1.1.2 — Variables, constants, assignment and sequence

Retrieval: the previous lesson introduced data types (int, float, bool, str) - every variable you declare here will hold a value of one of those types, so keep that vocabulary in mind as you read on.

A variable is a named location in memory that can hold a value that may change while the program runs. A constant is a named value that should never change.

VAT_RATE = 0.20      # constant - by convention, written in capitals
price = 19.99         # variable
total = price * (1 + VAT_RATE)
print(total)

Sequence

Sequence is the simplest of the three programming constructs (alongside selection and iteration, which you'll meet properly in later lessons): instructions execute one after another, top to bottom, exactly once each.

name = input("What is your name? ")
greeting = "Hello, " + name
print(greeting)

Meaningful identifiers

Compare:

x = 82.5
y = x >= 70

with:

average_grade = 82.5
is_distinction = average_grade >= 70

The second version is self-documenting — a reader (including you, in six months) understands it without needing a comment. AQA's NEA marking criteria explicitly reward "meaningful identifier names" as part of good coding style (Table 2), so this habit matters beyond this lesson.

Common mistake

Assignment (=) is not the same as mathematical equality — total = total + 1 looks nonsensical as maths, but as an assignment it means "calculate the value on the right, then store it back into total", correctly incrementing the variable. Reading = as "becomes" rather than "equals" avoids this confusion.

Practise it yourself

Write a short sequential program that: declares a variable for your name, a constant for a fixed passing grade (e.g. PASS_MARK = 40), reads a score from the keyboard, and prints a greeting followed by whether that score is above the constant. Use meaningful identifier names throughout, and check that every line runs in the order you expect.

Looking ahead

Later in this sequence you'll meet selection (choosing which code runs) and iteration (repeating code), and in Sequence 3 you'll meet procedures and functions (packaging code for reuse). Every one of those still relies on the sequential execution you've just learned — selection and iteration just control which sequence of instructions runs and how many times.

Practise

Apply what you've just learned in the Coding Lab.

Open Coding Lab
Log in to track this lesson on your progress dashboard.
Log in