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.
Each code snippet below contains exactly one bug. Type the corrected line in the input box.
Bug 1 — Wrong file mode
Bug 2 — Missing type conversion
f.read() returns a string. The score must be a number to compare with >.Bug 3 — Wrong comparison operator
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.
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.
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?