Paper 2: Advanced file reading
Chapter practice with ten items, answers and a one-line note for each, about 25 minutes.
| 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 |
| # | 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. |
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.

