S4 ICT: Python Dictionaries and File Handling (Paper 2 (intermediate))
- 2026-11-14
Tutor Prep Guide · Dictionary key lookup and the get default, membership tests, update and counting, reading a file line by line with strip, word frequency statistics, number conversion and averages, plus the mistakes students repeat most often
S4 ICT: Python Dictionaries and File Handling (Paper 2 (intermediate))
Paper 2 (intermediate): 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)
- FoundationWith d = {‘a’: 1, ‘b’: 2} then d[‘a’] = 10, what is d[‘a’]?
- FoundationFor the same dictionary, what is the value of ‘b’ in d?
- FoundationFor the same dictionary, what is sum(d.values())?
- IntermediateAfter splitting to be or not to be into words, how often does be appear?
- IntermediateA file holds five lines: 10, 20, 30, 40 and 50. After converting each to an integer, what is the total?
- IntermediateWhat is the average of the values in {‘A’: 70, ‘B’: 80, ‘C’: 90}?
- ChallengeFor the same dictionary, which key does max(d, key=d.get) return?
- ChallengeA file holds three lines 60, 70 and 80. After converting to integers, what is the average?
- ChallengeWhat is the advantage of counting with d[k] = d.get(k, 0) + 1?
- Error redoWhy do string comparisons after readlines often fail?
03 Answers and one-line notes
| # | Answer | One-line note |
|---|---|---|
| 1 | 10 | Assigning to an existing key overwrites the old value, so it reads back as 10. |
| 2 | True | in tests keys. b is one of the keys, so it returns True. |
| 3 | 12 | values gives every value, and 1 plus 2 is 12. |
| 4 | 2 | There are six words and be sits in positions two and six, so 2 times. |
| 5 | 150 | Adding all five values gives 150 after converting each with int. |
| 6 | 80.0 | The three values add to 240, and dividing by 3 gives 80.0. |
| 7 | C | It compares the values; the largest is 90 and its key is C. |
| 8 | 70.0 | The total 210 divided by 3 gives 70.0, using float division to avoid truncation. |
| 9 | A new key starts from 0 automatically | get returns 0 for a missing key, so the first and later hits share one line and no KeyError is raised. |
| 10 | Every line still carries the newline | The trailing newline adds a character, so strip it before comparing. |
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.



