Skip to content
Computer Science · Class 12

Active learning ideas

Local and Global Scope in Python

Active learning helps students visualise how Python treats variables in different scopes by making the abstract concept concrete through hands-on code. When learners trace variable lifetimes and namespace isolation themselves, misconceptions about global access and local destruction surface immediately, allowing quick correction.

CBSE Learning OutcomesCBSE: Computational Thinking and Programming - Functions - Class 12
25–45 minPairs → Whole Class4 activities

Activity 01

Socratic Seminar30 min · Pairs

Pair Programming: Scope Error Hunt

Provide pairs with Python code containing mixed scope errors. They run the code, predict variable values at key points, then fix issues by declaring locals or using 'global'. Pairs test fixes and explain changes to another pair.

Differentiate between local and global variables in Python.

Facilitation TipIn Pair Programming: Scope Error Hunt, circulate and listen for pairs explaining why a NameError appeared, nudging them to connect the error to scope rules.

What to look forPresent students with three short Python code snippets, each demonstrating a different scope scenario (e.g., accessing a global, modifying a global without 'global', defining a local). Ask students to predict the output and explain their reasoning for each snippet.

AnalyzeEvaluateCreateSocial AwarenessRelationship Skills
Generate Complete Lesson

Activity 02

Socratic Seminar45 min · Small Groups

Small Groups: Modular Bank Simulator

Groups build a banking programme with functions for deposit, withdraw, and balance check. Use local variables for transactions, one global for account balance. Modify to test scope impacts, then refactor to minimise globals.

Analyze the potential risks of overusing global variables in a program.

Facilitation TipDuring the Modular Bank Simulator, ask groups to physically separate global and local areas on paper to reinforce namespace boundaries.

What to look forProvide students with a function that attempts to modify a global variable without using the 'global' keyword. Ask them to rewrite the function correctly and explain in one sentence why the original code would not work as intended.

AnalyzeEvaluateCreateSocial AwarenessRelationship Skills
Generate Complete Lesson

Activity 03

Socratic Seminar25 min · Whole Class

Whole Class: Prediction Relay

Display code snippets on the board. Students predict output for local/global access in turns, vote on answers, then run code to verify. Discuss discrepancies as a class.

Justify the use of local variables for data encapsulation within functions.

Facilitation TipIn the Prediction Relay, insist each student writes their prediction before running code, making silent thinkers accountable.

What to look forPose the question: 'When might it be acceptable, or even necessary, to use a global variable in a Python program? Discuss potential downsides and how to mitigate them.' Encourage students to share examples and justify their arguments.

AnalyzeEvaluateCreateSocial AwarenessRelationship Skills
Generate Complete Lesson

Activity 04

Socratic Seminar35 min · Individual

Individual: Scope Refactor Challenge

Give each student a programme overusing globals. They refactor to locals where possible, document changes, and note improvements in readability. Submit for peer review.

Differentiate between local and global variables in Python.

Facilitation TipFor the Scope Refactor Challenge, provide a checklist of unsafe patterns so strugglers can spot issues before rewriting.

What to look forPresent students with three short Python code snippets, each demonstrating a different scope scenario (e.g., accessing a global, modifying a global without 'global', defining a local). Ask students to predict the output and explain their reasoning for each snippet.

AnalyzeEvaluateCreateSocial AwarenessRelationship Skills
Generate Complete Lesson

A few notes on teaching this unit

Experienced teachers begin with concrete, runnable examples where the same variable name appears in global and local scopes, then force students to predict outputs before execution. Avoid abstract lectures; instead, use deliberate debugging to expose fragile mental models. Research shows students grasp scope best when they repeatedly observe how Python’s LEGB rule resolves names, so build activities that make the interpreter’s decisions visible.

By the end of this hub, students will confidently predict scope outcomes, justify decisions with examples, and refactor unsafe global usage. You should see students pointing to line numbers, debating fixes, and using print statements to confirm their understanding.


Watch Out for These Misconceptions

  • During Pair Programming: Scope Error Hunt, watch for pairs assuming every variable inside a function is global by default.

    Have pairs annotate each variable in their snippets with a sticky note: 'G' for global or 'L' for local before they run the code, then verify with actual outputs.

  • During Modular Bank Simulator small groups, listen for students believing local variables remain alive after the function exits.

    Ask groups to insert a print statement right after the function call that tries to access the local variable; the NameError will make the destruction visible.

  • During class debates in Scope Refactor Challenge, notice students suggesting 'global' as the first fix for any cross-function access.

    Require each suggestion to include a justification slide with at least two alternatives before accepting 'global', linking back to the bank simulator’s shared state risks.


Methods used in this brief