What coding really is
Coding is writing precise instructions for a computer. Every program, from a calculator to a video game, is built from the same small set of ideas. Learn these well and any language becomes easier.
Variables and data types
A variable is a named store for a value that can change. Every value has a data type.
| Data type | Holds | Example |
|---|---|---|
| Integer | Whole numbers | age = 15 |
| Real (float) | Decimal numbers | price = 2.99 |
| String | Text | name = "Sam" |
| Boolean | True or False | passed = True |
| Character | A single character | grade = "A" |
A constant is a value that does not change while the program runs, such as VAT_RATE.
Sequence
Instructions run in order, top to bottom. Changing the order changes the result.
Selection
if score >= 50:
print("Pass")
elif score >= 40:
print("Nearly there")
else:
print("Try again")
Iteration
Count-controlled loops run a set number of times. Condition-controlled loops run until something changes.
for i in range(5):
print("Hello")
password = ""
while password != "letmein":
password = input("Password: ")
Operators
+ - * / | Add, subtract, multiply, divide |
// (DIV) | Whole number division: 17 // 5 = 3 |
% (MOD) | Remainder: 17 % 5 = 2 |
** | Power: 2 ** 3 = 8 |
== != < > <= >= | Comparisons |
and or not | Boolean operators |
Functions and procedures
A subroutine is a named block of code you can reuse. A function returns a value; a procedure does not.
def area(width, height):
return width * height
print(area(4, 5))
Local variables exist only inside a subroutine. Global variables can be used anywhere, but make programs harder to debug.
Lists and arrays
scores = [12, 18, 9]
print(scores[0]) # 12, positions start at 0
scores.append(15)
print(len(scores)) # 4
Decomposition and abstraction
Decomposition breaks a big problem into smaller ones. Abstraction removes detail that does not matter. A map of the London Underground is a famous abstraction: it ignores real distances so you can see the connections.
Writing robust programs
- Validation: check input is sensible, such as an age between 0 and 120.
- Testing: use normal, boundary and erroneous data.
- Maintainability: meaningful names, comments and indentation.

