Skip to content
Computing · Year 9

Active learning ideas

Scope of Variables (Local vs. Global)

Active learning helps Year 9 students grasp variable scope by making abstract concepts concrete through hands-on program building. When students predict, test, and debug code, they move beyond memorization to internalize how local and global variables behave in real programs.

National Curriculum Attainment TargetsKS3: Computing - Programming and Development
20–45 minPairs → Whole Class4 activities

Activity 01

Think-Pair-Share30 min · Pairs

Pair Prediction Challenge: Scope Shadows

Pairs write a Python function that modifies a variable with the same name as a global one. They predict printed outputs on paper first, then code and run to compare. Discuss differences and rewrite using parameters.

Explain the difference between local and global variables in a Python program.

Facilitation TipDuring Pair Prediction Challenge, circulate and ask each pair to explain their prediction reasoning before running the code together.

What to look forPresent students with a short Python code snippet containing both local and global variables, some with identical names. Ask them to write down the predicted output and circle the variables they identify as global and underline those they identify as local.

UnderstandApplyAnalyzeSelf-AwarenessRelationship Skills
Generate Complete Lesson

Activity 02

Think-Pair-Share45 min · Small Groups

Small Group Debug Relay: Global Pitfalls

Provide buggy code snippets overusing globals. Groups divide tasks: one identifies scope errors, another predicts fixes, third tests in IDLE. Rotate roles and share solutions with class.

Predict the output of a program that uses both local and global variables with the same name.

Facilitation TipIn Small Group Debug Relay, assign each group a unique error to fix, then rotate roles so every student practices debugging live syntax and logic errors.

What to look forPose the question: 'Imagine you are building a program with 10 functions. What are the risks of declaring all variables as global? How could you make the program more robust by using local variables instead?' Facilitate a class discussion on the pros and cons.

UnderstandApplyAnalyzeSelf-AwarenessRelationship Skills
Generate Complete Lesson

Activity 03

Think-Pair-Share25 min · Whole Class

Whole Class Live Code-Along: Scope Demo

Project a script with local/global vars. Class votes on outputs before running. Alter code live to demonstrate changes, then students recreate independently.

Analyze the potential pitfalls of overusing global variables in modular programming.

Facilitation TipFor Whole Class Live Code-Along, pause after each new variable declaration to poll the class on whether it is local or global, using hand signals for quick feedback.

What to look forAsk students to write down one key difference between local and global variables. Then, have them describe a scenario where using a global variable might be acceptable, and a scenario where it would be problematic.

UnderstandApplyAnalyzeSelf-AwarenessRelationship Skills
Generate Complete Lesson

Activity 04

Think-Pair-Share20 min · Individual

Individual Refactor Worksheet: Modular Makeover

Students receive code heavy on globals. Identify issues, convert to local vars with arguments/returns, and test outputs match originals.

Explain the difference between local and global variables in a Python program.

What to look forPresent students with a short Python code snippet containing both local and global variables, some with identical names. Ask them to write down the predicted output and circle the variables they identify as global and underline those they identify as local.

UnderstandApplyAnalyzeSelf-AwarenessRelationship Skills
Generate Complete Lesson

A few notes on teaching this unit

Teach scope by starting with students’ lived experience of names in groups—local to a conversation, global across a school. Use concrete analogies like sticky notes that vanish when the function ends versus posters on the classroom wall. Avoid overloading with formal definitions early; let patterns emerge through repeated exposure in varied contexts.

Successful learning looks like students confidently identifying variable scope, predicting program outputs, and explaining shadowing through evidence from their own code. They should articulate why modular designs with local variables improve program safety and clarity.


Watch Out for These Misconceptions

  • During Pair Prediction Challenge, watch for students who assume all variables remain accessible after their function ends.

    Have pairs run their code and observe the 'NameError' when they try to access a local variable outside its function. Ask them to revise their predictions based on the error message.

  • During Small Group Debug Relay, listen for groups claiming a local variable permanently overwrites a global one with the same name.

    Direct groups to add print statements that display the global variable value before and after the function call, showing it remains unchanged.

  • During Whole Class Live Code-Along, watch for students who think the 'global' keyword is needed just to read a global variable.

    Run a live demo where students vote on the output of a read-only global access, then test it without 'global' to confirm it works, contrasting with an assignment case that does require it.


Methods used in this brief