One Week Out โ€” What Actually Moves the Needle

With 7 days to HKDSE ICT, don't try to learn new topics. Instead, drill these 10 high-yield Python techniques that appear on virtually every paper.

1. Master f-string Formatting

name = "Chan"
score = 87.5
print(f"{name}: {score:.1f}")    # Chan: 87.5
print(f"{name:<10}{score:>5.2f}")  # Right-align numbers

2. Memorise the range() Patterns

range(5)          # 0, 1, 2, 3, 4
range(1, 6)       # 1, 2, 3, 4, 5
range(0, 10, 2)   # 0, 2, 4, 6, 8
range(10, 0, -1)  # 10, 9, 8, ..., 1

3. List Methods Cheat Sheet

lst = [3, 1, 4, 1, 5]
lst.append(9)       # [3,1,4,1,5,9]
lst.sort()          # [1,1,3,4,5,9]
lst.reverse()       # [9,5,4,3,1,1]
lst.count(1)        # 2
lst.index(4)        # 2 (position)

4. String Slicing Tricks

s = "HKDSE"
s[0]      # "H"
s[-1]     # "E" (last char)
s[::-1]   # "ESDKH" (reversed)
s[1:4]    # "KDS"
s[:2]     # "HK"
s[2:]     # "DSE"

5. Always Convert input()

input() always returns a string. The first line you write should typically convert it:

age = int(input("Age: "))     # For integers
fee = float(input("Fee: "))   # For decimals
# Never forget this โ€” it's a 1-mark trap

6. The "Collect-Then-Process" Pattern

For many HKDSE problems, collect inputs into a list first, then process:

scores = []
for i in range(5):
    scores.append(int(input(f"Score {i+1}: ")))
print(f"Average: {sum(scores)/len(scores):.1f}")
print(f"Highest: {max(scores)}")

7. Counting with Dictionaries

text = "hello world"
counts = {}
for char in text:
    counts[char] = counts.get(char, 0) + 1
print(counts)

8. 2D List Navigation

grid = [[1,2,3], [4,5,6], [7,8,9]]
# Access row r, column c: grid[r][c]
print(grid[1][2])  # 6

# Iterate all cells
for row in grid:
    for val in row:
        print(val, end=" ")

9. Function Return Shorthand

def grade(score):
    if score >= 80: return 'A'
    if score >= 65: return 'B'
    if score >= 50: return 'C'
    return 'F'
# return exits the function โ€” no elif needed

10. File Reading Template

with open('data.txt') as f:
    for line in f:
        line = line.strip()   # Remove \n
        if line:              # Skip empty lines
            # process line
            print(line)

Final Day Routine

Drill These Patterns with PyForm

Every technique here can be practised instantly in PyForm's browser IDE. No setup, no distractions.

Open PyForm โ†’