Pseudocode Conventions in HKDSE
INPUT xβx = input()(convert type as needed).OUTPUT xβprint(x).IFβ¦THENβ¦ELSEβ¦ENDIFβif/elseblock.FOR i FROM 1 TO 10βfor i in range(1, 11).WHILE condition DO β¦ END WHILEβwhile condition:.
Example 1 β Sum of N
INPUT n
total β 0
FOR i FROM 1 TO n
total β total + i
END FOR
OUTPUT total
n = int(input())
total = 0
for i in range(1, n + 1):
total += i
print(total)
Example 2 β Linear Search
found β FALSE
FOR each x IN list
IF x = target THEN
found β TRUE
EXIT FOR
END IF
END FOR
found = False
for x in lst:
if x == target:
found = True
break
Tips
- Declare types in Python at first assignment β pseudocode types are implicit.
- Use
rangewith the exclusive upper bound. - Mirror pseudocode variable names to score follow-through marks.
Practise this on PyForm β free
PyForm runs Python in your browser with an AI tutor trained for HKDSE. No install, no credit card.
Open PyForm β