Why Output Format Matters

HKDSE awards output marks only for exact matches. A trailing space, missing newline, or wrong decimal count loses marks.

Basic print()

print("Hello")          # "Hello" + newline
print("A", "B")         # "A B" (default space separator)
print("A", "B", sep="-") # "A-B"
print("A", end="")      # No newline after
print("B")              # So "AB" on one line

f-string Essentials

name = "Chan"
score = 87.5

print(f"{name}: {score}")          # "Chan: 87.5"
print(f"{name}: {score:.1f}")      # "Chan: 87.5" (1 decimal)
print(f"{name}: {score:.0f}")      # "Chan: 88" (rounded)
print(f"{name}: {score:.2f}")      # "Chan: 87.50"

Alignment and Width

for name, score in [("Chan", 85), ("Li", 92)]:
    print(f"{name:<10}{score:>5}")

# Chan          85
# Li            92

Zero Padding

print(f"{7:03}")       # "007"
print(f"{42:05}")      # "00042"

Currency / Large Numbers

price = 1234567
print(f"${price:,}")    # "$1,234,567"
print(f"{0.875:.1%}")   # "87.5%"

Multi-Line Output

# Use \n for newlines
print("Line 1\nLine 2\nLine 3")

# Or triple quotes
print("""Line 1
Line 2
Line 3""")

HKDSE-Common Patterns

# Pattern: Named data
for s in students:
    print(f"Name: {s[0]}, Score: {s[1]}")

# Pattern: Table
print(f"{'Name':<10}{'Score':>6}")
print("-" * 16)

# Pattern: Number with units
total = 125.5
print(f"Total: ${total:.2f}")
# "Total: $125.50"

Common Output Mistakes

Verify Output Exactly in PyForm

Run your code and copy the output. Compare character-by-character with the question's expected output.

Test Output โ†’