Quiz: Read and Write Text Files
Explore file handling in Python by taking a quiz on reading, writing, and appending text files. Learn how to manage files safely and apply these skills by building a score logger program that stores user data and displays a leaderboard.
We'll cover the following...
In the last lesson, you gave your Python programs long-term memory by reading from and writing to text files! You learned how to:
Write data using a mode
"w".Append content using mode
"a".Read data back using
.read().Use
withto handle files safely and cleanly.
Now, check what you’ve learned with a quick quiz!
What happens when you open a file with mode "w" in Python?
Reads the file without changing it
Opens the file for writing and overwrites existing content
Appends new content to the file
Nice job! You’ve just unlocked a powerful feature—file handling—that allows your Python programs to save and retrieve information between runs.
What’s next?
Let’s put your new skills into action! In this hands-on project, you’ll build a score logger that:
Prompts users for their name and score.
Saves the entries to a file called
scores.txtusing append mode.Reads and displays all stored scores so the user can see the full leaderboard.
This project gives your code a memory and turns it into a mini high-score board. Let’s start logging like a pro!