/en-tutor-prep-s5-ict-file-handling-exceptions-practice-2/
/en-tutor-prep-s5-ict-file-handling-exceptions-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

Paper 2: Advanced file reading

Paper 2: Advanced file reading

  • 2026-11-21

Paper 2: Advanced file reading

Chapter practice with ten items, answers and a one-line note for each, about 25 minutes.

Paper 2 Ten items on this chapter with answers for immediate marking.

01 Paper details (check answers afterwards)

Item Detail
Questions 10
Suggested time 25
Difficulty mix Foundation 4 · Intermediate 2 · Challenge 2 · Error redo 2
Chapter Chapter: File handling and exceptions
Level Advanced

02 Questions (10 items)

  1. FoundationA file has 1200 lines and you read 100 lines at a time; how many reads?
  2. FoundationHow many readline() calls read a 500-line file to the end?
  3. FoundationThree strings “15”, “28” and “42” are read and converted to integers; what is the sum?
  4. FoundationFrom the previous item, what is the mean to two decimal places?
  5. IntermediateA file has a header line plus 290 data lines; how many lines in total?
  6. IntermediateWhich exception does int(‘abc’) raise?
  7. ChallengeA list has 4 elements but index 5 is read; which exception is raised?
  8. ChallengeReading a missing key “total” from a dictionary raises which exception?
  9. Error redoIf the try block raises nothing, does the finally block still run?
  10. Error redoDoes readlines() on a 300-line file load everything at once or line by line?

03 Answers and one-line notes

# Answer One-line note
1 12 reads. 1200 divided by 100 gives 12, exactly.
2 500 calls. Each call returns one line, so calls equal lines.
3 85. Read data arrives as strings, so convert with int() before adding.
4 28.33. 85 divided by 3 gives 28.33 when rounded to two decimals.
5 291 lines. 290 plus 1 gives 291; skip the header when parsing.
6 ValueError. A failed conversion is a value error; catch it and log that line.
7 IndexError. Out-of-range indexing is an IndexError; check with len() first.
8 KeyError. A missing key is a KeyError; get() can supply a default.
9 Yes, it runs. finally always runs, which suits closing files or connections.
10 Everything at once, all 300 lines. It returns a list of 300 elements, so large files suit a line loop 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.

Want the whole chapter? See all four difficulty papers on the chapter page.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.

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