Lesson Plan

Lesson Plan
Grade: Date: 17/01/2026
Subject: Computer Science
Lesson Topic: Open, close and use a file for reading and writing
Learning Objective/s:
  • Describe the purpose and benefits of using files in programs.
  • Explain the different file opening modes and their appropriate use cases.
  • Demonstrate how to open, read, write, and close files safely using Python syntax.
  • Identify and correct common file‑handling errors such as missing files or forgetting to close.
Materials Needed:
  • Projector or interactive whiteboard
  • Computer lab with Python IDE (e.g., IDLE, VS Code)
  • Sample text files (scores.txt, log.txt)
  • Handout summarising file modes and common methods
  • Whiteboard markers
Introduction:
Begin with a quick discussion: why can’t all data be stored in variables alone? Recall how programs lose data when they stop running. Explain that today’s lesson will focus on using files to store and retrieve information, and students will be able to demonstrate correct file handling by the end.
Lesson Structure:
  1. Do‑now (5'): Students list situations where data must persist between program runs. (Engage)
  2. Mini‑lecture (10'): Explain why files are needed and introduce file modes with examples. (Explain)
  3. Guided demo (15'): Live coding opening a file, reading lines, and closing; students follow on their computers. (Explore)
  4. Pair activity (15'): Students modify a provided script to append a new record to a log file, testing different modes. (Apply)
  5. Error‑hunt challenge (10'): Teams debug a snippet that fails to close a file or uses the wrong mode, discussing fixes. (Evaluate)
  6. Quick recap quiz (5'): Kahoot or show‑of‑hands questions on mode selection. (Check)
Conclusion:
Summarise the three‑step file workflow (open → read/write → close) and revisit the key file modes. Students complete a brief exit ticket writing the correct mode for a given scenario. Assign homework to create a small program that logs user activity to a file.