Learn From Others' Mistakes
We analysed thousands of HKDSE ICT scripts. These 15 mistakes appeared most often — and each cost students 1 to 3 marks. Know them. Avoid them.
1. Forgetting to Cast input()
n = input("Enter n: ")
print(n * 2) # "55" instead of 10 if user enters 5
Fix: n = int(input(...))
2. Using = Instead of ==
if x = 5: # SyntaxError if x == 5: # ✓
3. Indentation Inconsistency
Mixing tabs and spaces causes invisible errors. Use 4 spaces consistently.
4. Off-by-One in range()
# Want 1 to 10 inclusive range(1, 10) # Only 1 to 9 ✗ range(1, 11) # 1 to 10 ✓
5. Modifying a List While Iterating
lst = [1,2,3,4,5]
for x in lst:
if x % 2 == 0:
lst.remove(x) # ✗ Skips elements
Fix: iterate over lst[:] (a copy) or use list comprehension.
6. Confusing append() and extend()
a = [1,2] a.append([3,4]) # [1,2,[3,4]] a = [1,2] a.extend([3,4]) # [1,2,3,4]
7. Integer vs Float Division
print(10 / 3) # 3.3333... print(10 // 3) # 3 (integer division)
8. Returning Inside a Loop Too Early
def find_max(lst):
for x in lst:
return x # ✗ Returns first element only
# Correct logic needs max comparison
9. Not Handling Empty Input
scores = []
print(sum(scores)/len(scores)) # ZeroDivisionError
if len(scores) > 0:
print(sum(scores)/len(scores))
10. String vs List Confusion
s = "hello"
s[0] = "H" # ✗ strings are immutable
s = list("hello")
s[0] = "H"
"".join(s) # "Hello"
11. Missing return Statement
def double(x):
x * 2 # ✗ Does nothing — no return
def double(x):
return x * 2 # ✓
12. Global vs Local Variables
count = 0
def increment():
count += 1 # ✗ UnboundLocalError
def increment():
global count
count += 1 # ✓
13. File Not Closed
f = open('data.txt')
# ... use f ...
# forgot f.close() — loses a mark
# Better:
with open('data.txt') as f:
...
14. Incorrect String Comparison
grade = input("Grade: ")
if grade == "A": # ✓
if grade is "A": # ✗ Works sometimes, unreliable
15. Forgetting .strip() When Reading Files
with open('data.txt') as f:
for line in f:
if line == "END": # ✗ line is "END\n"
break
# Fix:
if line.strip() == "END": # ✓
break
⚠️ The top mistake: Not reading the question fully. Underline keywords like "integer", "2 decimal places", "uppercase" before writing a single line.
Test Your Code Before You Submit
Use PyForm to trace through every example from past papers. Catch these mistakes before the examiner does.
Open PyForm →