Year 9 Computing Revision Notes
Variables and Assignment
A variable is a named container that stores data that can change while a program is running.

Assignment Operator (
=): Assigns the value on the right to the variable on the left (e.g.,age = 14,name = "Ali",score = 72). Assigning a new value overwrites the existing value.Variable Naming Rules:
Use meaningful names (e.g.,
student_score).May contain letters, numbers, and underscores (
_).Must not start with a number.
Must not contain spaces or special symbols (such as
@,#,!,%,-).Case-sensitive (
scoreandScoreare distinct variables).
Data Types and Typecasting
Data types specify the kind of data stored in a program.

Data Types:
Integer (
int): Positive or negative whole numbers, including zero (e.g.,42,-12,0).Float (
float): Numbers with decimal points (e.g.,1.42,-0.002,4.0).String (
str): Text or characters inside quotation marks (e.g.,"Hello","Ken123").Boolean (
bool): Truth values (True,False).
User Input:
The
input()function captures user input and always returns it as a string (str).
Typecasting:
Typecasting is the process of converting a value from one data type to another.

Typecasting Functions:
int(): Converts to integer (e.g.,int("4"),int(3.7)).float(): Converts to floating-point number (e.g.,float(3),float("6.7")$I\rightarrow 6.7).\n * `str()`: Converts to string (e.g., `str(4)` \rightarrow \text{"4"}$$).bool(): Converts to boolean.bool(0)andbool("")evaluate toFalse; any non-zero number or non-empty string evaluates toTrue.
Formatted Strings (f-strings):
print(f"My name is {name}")provides formatted outputs embedding variables directly.
Algorithms and Pseudocode
An algorithm is a step-by-step sequence of instructions used to solve a problem, independent of programming languages.

Pseudocode Conventions:
Enclose programs between
STARTandENDkeywords.Use
DISPLAYto output messages or values.Use
INPUT()to receive user data.Use
←for variable assignment (e.g.,score ← 50).Group nested instructions for structures inside
{ }curly brackets.
Selection and Logical Operators
Conditional statements control program flow by making decisions based on truth conditions.
Comparison Operators:
=,>,<,>=,<=,!=(Python uses==for equality comparison).Logical Operators:
AND: Evaluates toTrueonly when both conditions are true.OR: Evaluates toTruewhen at least one condition is true.NOT: Inverts the truth value of a condition.
Conditional Structures: Evaluated in sequence using
IF,ELSE IF, andELSE. Processing halts for the statement block once a condition evaluates toTrue.
Loops and Iteration
Loops repeatedly execute a block of instructions.
Count-Controlled Loops:
Executed when the exact number of iterations is known in advance.
Pseudocode:
REPEAT n TIMES { ... }Python:
for i in range(start, stop):(e.g.,range(1, limit + 1)iterates up tolimit).
Condition-Controlled Loops:
Executed when iterations depend on an unknown number of repetitions until a condition is met.
Pseudocode:
REPEAT UNTIL (condition) { ... }Python:
whileloop.
Modulo Operator (
MOD): Calculates division remainders (e.g.,i MOD 2 = 0determines ifiis an even number).
Code Tracing
Tracing is a manual step-by-step execution of an algorithm to track and record variable modifications across iterations.

Tracing Rules:
Maintain initial variable values at start.
Evaluate expressions using old right-hand variable values before assigning the updated result to left-hand variables.
Record state changes systematically row-by-row in a trace table for every iteration.