Quiz: Read and Write Text Files
Review and test your knowledge of Python file handling with this quiz. Understand how to read from, write to, and append text files safely using Python's file modes and context management. Gain confidence in giving your programs the ability to save and retrieve information effectively.
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!