/en-tutor-prep-s4-ict-python-dictionary-file-io-practice-2/
/en-tutor-prep-s4-ict-python-dictionary-file-io-practice-2/
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 2 (intermediate))

S4 ICT: Python Dictionaries and File Handling (Paper 2 (intermediate))

  • 2026-11-14

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)

  1. FoundationWith d = {‘a’: 1, ‘b’: 2} then d[‘a’] = 10, what is d[‘a’]?
  2. FoundationFor the same dictionary, what is the value of ‘b’ in d?
  3. FoundationFor the same dictionary, what is sum(d.values())?
  4. IntermediateAfter splitting to be or not to be into words, how often does be appear?
  5. IntermediateA file holds five lines: 10, 20, 30, 40 and 50. After converting each to an integer, what is the total?
  6. IntermediateWhat is the average of the values in {‘A’: 70, ‘B’: 80, ‘C’: 90}?
  7. ChallengeFor the same dictionary, which key does max(d, key=d.get) return?
  8. ChallengeA file holds three lines 60, 70 and 80. After converting to integers, what is the average?
  9. ChallengeWhat is the advantage of counting with d[k] = d.get(k, 0) + 1?
  10. 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.

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