AI Features

Quiz: Read and Write Text Files

Test how to read, write, and append text files in Python

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!

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

Question 1 of 30 attempted

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!