Search⌘ K
AI Features

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 with to handle files safely and cleanly.

Now, check what you’ve learned with a quick quiz!

Technical Quiz
1.

What happens when you open a file with mode "w" in Python?

A.

Reads the file without changing it

B.

Opens the file for writing and overwrites existing content

C.

Appends new content to the file


1 / 3

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.txt using 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!