Powers of 2
Memorise up to 2^10 = 1024. Shifts appear in bitwise questions.
Modulo Shortcuts
n % 2โ parity (0 = even).n % 10โ last digit.n // 10โ drop the last digit.
Integer Division Tricks
n // 2โ halve (floor).n * 10 + dโ append a digit.
Digit Sum in 2 Lines
def digit_sum(n):
return sum(int(c) for c in str(abs(n)))
Rounding Quick Wins
round(x, 2)โ 2 decimals (banker's rounding).int(x)โ truncate toward zero.math.floor(x)โ toward negative infinity.
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 โ