← AQA GCSE
AQA pseudo-code and Python side by side
Comment
# comment
# comment
Assignment
a ← 3
c ← 'Hello'
a = 3
c = 'Hello'
Constant
CONSTANT PI ← 3.141
PI = 3.141 # constant by naming convention
User input
name ← USERINPUT
name = input()
Output
OUTPUT name
OUTPUT a, b
print(name)
print(a, b)
Arithmetic operators
+ - * /
+ - * /
Integer division and remainder
9 DIV 5 # 1
9 MOD 5 # 4
9 // 5 # 1
9 % 5 # 4
Relational operators
= ≠ < > ≤ ≥
== != < > <= >=
Boolean operators
(x < 1) OR (x > 9)
(3 = 3) AND (3 ≤ 4)
NOT (a < b)
(x < 1) or (x > 9)
(3 == 3) and (3 <= 4)
not (a < b)
Count-controlled loop
FOR i ← 1 TO 5
OUTPUT i
ENDFOR
for i in range(1, 6):
print(i)Count-controlled loop with STEP
FOR a ← 5 TO 1 STEP -2
OUTPUT a
ENDFOR
for a in range(5, 0, -2):
print(a)Loop over a string or array
FOR ch IN message
OUTPUT ch
ENDFOR
for ch in message:
print(ch)WHILE loop (checks first)
WHILE a < 4
OUTPUT a
a ← a + 1
ENDWHILE
while a < 4:
print(a)
a = a + 1REPEAT UNTIL loop (runs at least once)
REPEAT
OUTPUT a
a ← a + 1
UNTIL a = 4
while True:
print(a)
a = a + 1
if a == 4:
breakIF, ELSE IF, ELSE
IF x MOD 4 = 0 THEN
OUTPUT 'multiple of 4'
ELSE IF x MOD 4 = 1 THEN
OUTPUT 'remainder 1'
ELSE
OUTPUT 'other'
ENDIF
if x % 4 == 0:
print('multiple of 4')
elif x % 4 == 1:
print('remainder 1')
else:
print('other')Array assignment and access (0-indexed)
primes ← [2, 3, 5, 7]
primes[0]
primes[3] ← 11
primes = [2, 3, 5, 7]
primes[0]
primes[3] = 11
2D array
table ← [[1, 2], [3, 4]]
table[1][0] ← 9
table = [[1, 2], [3, 4]]
table[1][0] = 9
Length of an array or string
LEN(primes)
LEN('computer')len(primes)
len('computer')Position of a character
POSITION('computer', 'm') # 2'computer'.index('m') # 2Substring (start and END positions, both included)
SUBSTRING(2, 5, 'computer') # 'mput'
'computer'[2:6] # 'mput' (slice end is one past)
Concatenation
'computer' + 'science'
'computer' + 'science'
String and number conversion
STRING_TO_INT('16')
STRING_TO_REAL('16.3')
INT_TO_STRING(16)
REAL_TO_STRING(16.3)int('16')
float('16.3')
str(16)
str(16.3)Character codes
CHAR_TO_CODE('a') # 97
CODE_TO_CHAR(97) # 'a'ord('a') # 97
chr(97) # 'a'Procedure (no RETURN)
SUBROUTINE showAdd(a, b)
OUTPUT a + b
ENDSUBROUTINE
showAdd(2, 3)
def showAdd(a, b):
print(a + b)
showAdd(2, 3)Function (has RETURN)
SUBROUTINE add(a, b)
RETURN a + b
ENDSUBROUTINE
answer ← add(2, 3)
def add(a, b):
return a + b
answer = add(2, 3)Record declaration
RECORD Car
make : String
price : Real
ENDRECORD
class Car:
def __init__(self, make, price):
self.make = make
self.price = priceCreate a record and use its fields
myCar ← Car('Ford', 1399.99)
myCar.price ← 1200.0
OUTPUT myCar.makemyCar = Car('Ford', 1399.99)
myCar.price = 1200.0
print(myCar.make)Random integer (both limits included)
roll ← RANDOM_INT(1, 6)
import random
roll = random.randint(1, 6)