S4 ICT: Python Dictionaries and File Handling (Paper 1 (basics))
- 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 1 (basics))
Paper 1 (basics): 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)
- FoundationFor d = {‘a’: 1, ‘b’: 2}, what is len(d)?
- FoundationFor the same dictionary, what is d[‘a’] + d[‘b’]?
- FoundationFor the same dictionary, what does d.get(‘c’, 0) return?
- IntermediateWith d = {‘x’: 10} then d[‘y’] = 5, what is d[‘x’] + d[‘y’]?
- IntermediateWith d = {‘a’: 1} then d.update({‘b’: 2, ‘c’: 3}), what is len(d)?
- IntermediateHow many items does f.readlines() return for a text file with three lines?
- ChallengeCounting the words in the text a a b, how many times does a appear?
- ChallengeWhich method removes the trailing newline from each line read from a file?
- ChallengeA file holds only the string 12; after converting with int and adding 8, what is the result?
- Error redoKey c does not exist; what happens when you write d[‘c’]?
03 Answers and one-line notes
| # | Answer | One-line note |
|---|---|---|
| 1 | 2 | len of a dictionary returns the number of key value pairs, and there are two keys here. |
| 2 | 3 | Take the two values by key and add them: 1 + 2 gives 3. |
| 3 | 0 | Key c is missing, so get returns the given default 0 instead of raising an error. |
| 4 | 15 | After adding the key both values are readable, and 10 + 5 gives 15. |
| 5 | 3 | update adds two new keys, so together with the original one there are 3. |
| 6 | 3 | readlines gives one string per line, so three lines become 3 items. |
| 7 | 2 | After splitting into three words, a appears 2 times and b once. |
| 8 | strip() | strip() drops the newline and spaces at both ends, so later comparisons and conversions work. |
| 9 | 20 | Convert the string to an integer first, then 12 + 8 gives 20. |
| 10 | It raises KeyError | Square bracket lookup requires the key to exist; use get or test with in first. |
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.



