Lesson Plan

Lesson Plan
Grade: Grade 10 Date: 17/01/2026
Subject: Computer Science
Lesson Topic: Understand and use local and global variables
Learning Objective/s:
  • Describe the concept of variable scope and differentiate between local and global variables.
  • Explain the advantages and disadvantages of using global variables.
  • Apply the appropriate scope by writing code that uses local variables and, where necessary, global variables in Python or Java.
  • Identify and correct common pitfalls such as variable shadowing and unintended side‑effects.
  • Evaluate code snippets to determine the output based on variable scope.
Materials Needed:
  • Projector or interactive whiteboard
  • Laptop with Python and Java IDEs installed
  • Printed handout of scope comparison table
  • Sample code worksheets (Python & Java)
  • Quiz sheets for quick assessment
  • Markers and whiteboard
Introduction:

Begin with a short poll asking students where they think a variable “lives” in a program. Review that variables have a type, name, and value, and link this to prior lessons on data types. State that by the end of the lesson they will be able to choose the correct scope and justify their choice.

Lesson Structure:
  1. Do‑now (5'): Students answer the quick quiz on variable scope on a worksheet.
  2. Mini‑lecture (10'): Review definitions of local vs. global scope, lifetime, and visibility using slides and the comparison table.
  3. Guided coding demo (15'): Show a Python global‑variable example, then refactor it to use a local variable; repeat the same concept in Java.
  4. Pair programming activity (15'): Learners modify provided code snippets to replace unnecessary globals with locals and document their changes.
  5. Class discussion & misconception check (10'): Highlight common pitfalls (shadowing, accidental modification) and have pairs share solutions.
  6. Exit ticket (5'): Each student writes one best‑practice rule for using globals responsibly.
Conclusion:

Recap the key differences between local and global variables and why scope matters for readability and debugging. Collect exit tickets to gauge understanding, and assign a short homework task: rewrite a given program to eliminate all unnecessary global variables.