S4 ICT: Python Dictionaries and File Handling (Paper 4 (error clinic))
- 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 4 (error clinic))
Paper 4 (error clinic): 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)
- FoundationKey c is missing; how do you avoid the error when reading d[‘c’]?
- FoundationA file line reads 12 plus a newline; what happens with a direct int() call?
- FoundationWhat is the safest way to avoid forgetting close after opening a file?
- IntermediateWhat is the value of the dictionary {1: ‘a’, 1: ‘b’}?
- IntermediateWhat goes wrong if you use the assignment sign = for comparison?
- IntermediateWhat is the difference between read() and readlines()?
- ChallengeWhen counting with d[w] = d[w] + 1, what happens the first time a new word appears?
- ChallengeWhat do you get by adding the two strings 10 and 20 directly?
- ChallengeWhat is the result of the string comparison ’10’ < ‘9’?
- Error redoWhich error appears when the file path is wrong?
03 Answers and one-line notes
| # | Answer | One-line note |
|---|---|---|
| 1 | Use d.get(‘c’, default) | get returns a default for a missing key; testing with in is the other safe option. |
| 2 | It raises ValueError | int cannot parse the stray newline, so strip the line before converting. |
| 3 | Use with open(…) as f | The with block closes the file automatically, even when an exception occurs. |
| 4 | ‘b’ | A repeated key keeps the later value, so it holds b and only one key. |
| 5 | Wrong logic or SyntaxError | Comparison needs ==; a single = assigns, so an if condition either fails or is always true. |
| 6 | read returns one big string, readlines a list of lines | Use readlines to work line by line and read for the whole text at once. |
| 7 | It raises KeyError | The key does not exist yet, so start from get(w, 0) + 1. |
| 8 | The string 1020 | Adding strings joins them; convert with int first to get 30. |
| 9 | True | Strings compare character by character, and 1 is smaller than 9, so True. Convert with int for numeric order. |
| 10 | FileNotFoundError | A missing file raises FileNotFoundError; check the path and keep files beside the script for relative paths. |
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.



