/en-tutor-prep-s4-ict-python-dictionary-file-io-practice-3/
/en-tutor-prep-s4-ict-python-dictionary-file-io-practice-3/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

S4 ICT: Python Dictionaries and File Handling (Paper 3 (challenge))

S4 ICT: Python Dictionaries and File Handling (Paper 3 (challenge))

  • 2026-11-14

S4 ICT: Python Dictionaries and File Handling (Paper 3 (challenge))

Paper 3 (challenge): ten questions on Python dictionaries and file reading, with answers and notes.

Direct answers Level: S4 ICT; format: key lookup, get default, update and counting, line by line file reading, word frequency, number conversion.

01 Paper details (check answers afterwards)

Item Detail
Questions 10
Suggested time 20
Difficulty mix Foundation 3 · Intermediate 3 · Challenge 3 · Error redo 1
Chapter Chapter: S4 ICT: Python Dictionaries and File Handling
Level S4

02 Questions (10 items)

  1. FoundationIn {x: x * x for x in range(4)}, what is the value of key 3?
  2. FoundationWhat is the sum of all values in {x: x * x for x in range(5)}?
  3. FoundationHow many keys does {1: ‘a’, 1: ‘b’} have?
  4. Intermediatea = {‘x’: 1} and b = {‘x’: 9, ‘y’: 2}. After a.update(b), what are a[‘x’] and len(a)?
  5. IntermediateA data line Chan,85,Maths is split by comma; what integer do you get from the second field?
  6. IntermediateA file holds four lines 12, 7, 25 and 18. What is the difference between the largest and the smallest?
  7. ChallengeIn {‘A’: {‘math’: 80}, ‘B’: {‘math’: 95}}, what is B’s math score?
  8. ChallengeWhich word appears most often in red blue red green red?
  9. ChallengeWith counts = {‘red’: 3, ‘blue’: 1}, what is the first item of sorted(counts.items(), key=lambda kv: kv[1], reverse=True)?
  10. Error redoWhat happens if you add keys inside a for k in d loop?

03 Answers and one-line notes

# Answer One-line note
1 9 The comprehension squares each key, and 3 squared is 9.
2 30 The values are 0, 1, 4, 9 and 16, which add to 30.
3 1 Keys are unique, so the second 1 overwrites the first and only 1 key remains, with value b.
4 9 and 2 update overwrites the shared key and adds the new one, so a[x] becomes 9 and the length is 2.
5 85 Indexing starts at 0, so the second field is 85, still 85 after int conversion.
6 18 The largest is 25 and the smallest 7, a difference of 18.
7 95 Two level indexing takes key B then key math, giving 95.
8 red red appears three times while blue and green appear once each, so red wins.
9 (red, 3) Sorting by value in descending order puts red with 3 first, returned as a key value pair.
10 It raises RuntimeError Changing the size of a dictionary during iteration raises RuntimeError; iterate over a list copy instead.

04 What to do after marking

  • After marking, redo only the wrong items and write down which step went wrong (formula, unit, or misread number).
  • Repeat the same item two days later; move to the next paper only when both attempts are correct.
  • Parents only need the answer and note columns; there is no need to explain every item.

First ask where the data lives (a dictionary uses keys, a file uses lines), then choose len, get or a counting loop; strip the line ending after reading and convert strings to numbers before any arithmetic.Tutor Registration →

Questions and answers are written originally by the TutorZone team and are not taken from any school, publisher or examination authority paper. Every value is checked by computer.

© TutorZone · www.tutorzone.com.hk · For personal study and teaching use only.

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →