Home›Lesson Plans›Computer Science›Programming · Grade 10

File Input/Output

Tenth graders learn file input/output — reading data from files and writing data to them. Files let a program save information that lasts beyond a single run. They check the ideas, then read and write a file.

Grade 10File Input/Output50 minutes1 class periodCSTA / ISTEExplicit teaching4 StandardsCSTA
Start the Lesson
Assign or share this lesson

Copy link works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment.

Lesson at a Glance

Everything you need before the bell rings

Learning Objectives

Students will be able to…

  • ✓Read from a file.
  • ✓Write to a file.
  • ✓Make data persist.
  • ✓Close files properly.
Essential Question

How does a program save data so it’s still there next time?

0
Lesson Phases
0
Vocabulary Terms
0
Standards Aligned
0
Interactive Task
Check It · Interactive

File Input/Output

Project each one and have students answer about file I/O.

📄 Understand reading and writing filesTry it
Answer each question about file input/output.
The Lesson · Explicit teaching

50 minutes, five moves

Tap any phase to open the teacher moves and student actions.

1

Hook — Where Did It Go?

5 min

Your program saves a high score — but it’s gone when you restart. Why?

👩‍🏫 Teacher Moves

  • Pose the question.
  • Share ideas.
  • Set the goal.

🎒 Student Actions

  • Think.
  • Share.
  • Get ready.
2

Use — File I/O

12 min

Students learn.

👩‍🏫 Teacher Moves

  • Send students to File Input/Output.
  • Note files persist, variables do not.
  • Note close files.

🎒 Student Actions

  • Answer.
  • Note it.
  • Note it.
3

Modify — Read & Write

13 min

Students practice.

👩‍🏫 Teacher Moves

  • Open a file for reading.
  • Read its contents.
  • Open one for writing.

🎒 Student Actions

  • Open.
  • Read.
  • Write.
4

Create — Create

15 min

Students apply.

👩‍🏫 Teacher Moves

  • Write data to a file.
  • Read it back.
  • Use a ‘with’ block.

🎒 Student Actions

  • Write.
  • Read.
  • With.
5

Reflect — Reflect

5 min

Students close.

👩‍🏫 Teacher Moves

  • What does file I/O do?
  • How do you save data?
  • Complete the exit ticket.

🎒 Student Actions

  • Say it.
  • Say it.
  • Complete the exit ticket.
Standards Alignment

Built to the standards you report on

Aligned to the CSTA K-12 Computer Science Standards and the ISTE Standards for Students.

CSTA
3A-AP-14

Use file I/O in programs.

CSTA
3A-DA-09

Store and retrieve data.

CSTA
3A-AP-17

Test file-handling code.

ISTE
5c

Manage data in programs.

Differentiation

One lesson, every learner

Multilingual Learners

ELL / EMERGING READERS
  • Read/write diagram.
  • Frame: "a file keeps data ___."
  • Demo file I/O.

Support & Access

IEP / 504
  • Read a file only.
  • Use a sample file.
  • Use a template.

Stretch & Extend

GIFTED / EARLY FINISHERS
  • Read a CSV file.
  • Append to a file.
  • Handle a missing file.
Materials

What to gather

  • 📽️Screen / board
  • 📄Sample files
  • 💻File Input/Output
  • 💻Python
  • 📓Notebooks
  • 🎫Exit-ticket slips
Vocabulary

Key terms — hover for a quick definition

file I/Oreading and writing filesreadget data from a filewritesave data to a filepersistdata that lastsopenaccess a fileclosefinish with a filewith blockauto-closes a filepatha file’s location
Evaluate

Exit Ticket

Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students.

QUESTION 1
What does file I/O let a program do?
Read data from and write data to files.
QUESTION 2
How do you save data so it persists?
Write it to a file.
QUESTION 3
What should you do after opening a file?
Close it when done (or use a "with" block).

Reflect: file input/output.

Have students write data to a file and read it back. A printable file-I/O sheet is in the CS library.

Study · Flashcards

Study the key terms

Tap a card to flip it, then rate whether you knew it. Built from this lesson’s vocabulary.

🃏 File Input/OutputFlip
Card 1
Term
Tap to flip →
Meaning
0

Nice work!

Practice · Quiz

Check your understanding

A quick self-check with instant feedback, drawn from this lesson’s key terms.

📝 File Input/OutputQuiz
Score: 0
1 / 6
Question 1
0%

Nice work!

Practice · Worksheet

Printable worksheet

A print-and-go review sheet with a built-in answer key. Tap “Show answer key” to reveal answers, or print the clean version for students.

🖨️ File Input/OutputPrint
Name: ________________________
Date: ____________

Part A · Write the word that matches each meaning

Word bank: close, file I/O, open, path, persist, read, with block, write
  1. a file’s location
  2. save data to a file
  3. finish with a file
  4. reading and writing files
  5. get data from a file
  6. access a file
  7. data that lasts
  8. auto-closes a file

Part B · Show what you learned

  1. What does file I/O let a program do?
  2. How do you save data so it persists?
  3. What should you do after opening a file?
Answer key — Part A: 1) path · 2) write · 3) close · 4) file I/O · 5) read · 6) open · 7) persist · 8) with block
Part B: 1) Read data from and write data to files. 2) Write it to a file. 3) Close it when done (or use a "with" block).