🎯Calibrate
1Fill-in
2Debug
3Extend
4Create
🧠Concept
📓Reflect
👤 Your Details REQUIRED — fill in before you begin (★ = required)
Please fill in Name, Matric No., and Class before continuing.
🎯 Pre-Activity Calibration Complete this before unlocking the tiers
Before you start, predict how well you understand file handling in Python. This helps you track how your confidence and understanding grow!
5
Be honest — this is just for your own reflection later!



✏️ Tier 1 Fill in the Blanks — load & save high score 6 blanks. All must be correct to advance.

Complete the load_high_score() and save_high_score() functions by filling in the missing parts. Each blank is a single keyword, value, or function name.

SCORE_FILE = "highscore.txt" def load_high_score(): try: with open(SCORE_FILE, "___1___") as f: return ___2___(f.read().strip()) except FileNotFoundError: return ___3___ def save_high_score(score): best = ___4___() if score ___5___ best: with open(SCORE_FILE, "___6___") as f: f.write(str(score)) return True return False
1open(SCORE_FILE, "___") as f — file mode for reading
2return ___(f.read().strip()) — convert string to integer
3except FileNotFoundError: return ___ — default score if no file
4best = ___() — call the function that loads the score
5if score ___ best — only save if new score is higher
6open(SCORE_FILE, "___") as f — file mode for writing

🐛 Tier 2 Debug the File Handler 3 bugs hidden in the code. Fix each one. 2 attempts max.

Each code snippet below contains exactly one bug. Type the corrected line in the input box.

Bug 1 — Wrong file mode

with open(SCORE_FILE, "a") as f: # inside load_high_score
Hint: "a" is append mode. Which mode should load_high_score use to read?

Bug 2 — Missing type conversion

return f.read().strip() # should return a number
Hint: f.read() returns a string. The score must be a number to compare with >.

Bug 3 — Wrong comparison operator

if score < best: # should only save a NEW record
Hint: We only want to save the score if it is strictly higher than the best recorded so far.
REFLECTION Mid-Activity Reflection


🔧 Tier 3 Extend — Display & Reset Add a function to display the high score using an f-string.

The starter code gives you load_high_score(). Add a new function display_high_score() that prints the high score in a formatted message using an f-string, e.g.: High Score: 42. Also add a reset_high_score() function that deletes the file or writes 0 to it.

SCORE_FILE = "highscore.txt" def load_high_score(): try: with open(SCORE_FILE, "r") as f: return int(f.read().strip()) except FileNotFoundError: return 0 # Add your display_high_score() and reset_high_score() below:


🏆 Tier 4 Create — Full Score System Write a complete high score system from scratch.

Design a ScoreManager class (or a set of functions) that can: (1) load the high score from highscore.txt, (2) save a new high score only if it beats the current best, (3) display the result using an f-string, (4) handle FileNotFoundError gracefully. Include a short demo that simulates scores of [12, 45, 30, 67, 55] being submitted one by one.

SCORE_FILE = "highscore.txt" # Write your complete score system here: # - load, save, display functions (or a class) # - handle FileNotFoundError # - demo loop submitting scores [12, 45, 30, 67, 55]


🧠 Concept Concept Check — File I/O & Error Handling 5 multiple-choice questions. Answer all 5 then submit.

Test your understanding of file modes, the with statement, and try/except FileNotFoundError.

1. Which mode should be passed to open() to read an existing file?

2. What does try/except FileNotFoundError do in load_high_score()?

3. Why do we use with open(...) as f: instead of just f = open(...)?

4. What does int(f.read().strip()) do?

5. In save_high_score(score), why do we call load_high_score() first?

POST-ACTIVITY Post-Activity Calibration & Reflection
5
This is your self-estimate — be honest!



JOURNAL Reflective Journal — Step 8 (min 5 words per prompt)