Community resourceWorksheet
OCR H446 2.2.1 Variable scope
Part 5 of 14 · H446 2.2.1 · Programming techniques
Two variables can share a name and still be separate storage, which is where H446 2.2.1 scope questions usually turn. Using a live-stream overlay, this worksheet has students read names from the inside out, predict shadowing without running the code, then replace global state with an explicit parameter and return interface.
Students will:
- identify which local and global bindings are accessible at a given point
- predict the output of a program where a local name shadows a global one
- explain the difference between a global and a local variable of the same name
- refactor a function to receive state as parameters and return the updated value
- convert local state into a shared global, weighing one benefit against a drawback
Inside: 6 explanation cells, 1 multiple-choice question, 1 fill-in-the-blanks cell, 3 written answers and 2 Python tasks. 19 marks, about 30 to 45 minutes.
Series: H446 2.2.1 · Programming techniques, part 5 of 14.
Shared by Coding PathwayVerified teacher
- 13 cells
- About 30 minutes
- CC BY-SA 4.0
- Shared 31 Aug 2026
- Updated 1 Oct 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Variable scope
A variable's scope is the part of a program that can access it. A local variable belongs to one subprogram call, while a global variable can be accessed more widely. Two variables may have the same name but still be separate because they belong to different scopes.
By the end, you will be able to
- identify which local and global variable each statement accesses
- predict shadowing without treating same-named variables as shared
- explain side effects and drawbacks of excessive global state
- replace hidden global state with parameters and returned values
Worked scope reading
Read a name from the inside out. If a function assigns to score without selecting the global variable, that call creates or changes its local score. A separate global score can still exist outside the function. Returning the local result does not itself overwrite the global; the caller decides where to store the returned value.
A local variable is created for the call and is no longer available after that call ends. A global variable normally exists for the lifetime of the program. Therefore a complete prediction tracks score in global scope, score in the current function call and the destination of the returned result separately.
score = 10
def add_bonus(points):
score = points + 2
return score
new_score = add_bonus(5)
print(score)
print(new_score)Worked model: draw the boundary
The assignment inside add_bonus creates/uses the local score. It does not cross the function boundary to replace global score. The output is therefore 10 then 7.
For every scope trace, write variable name and scope, for example score(global) and score(add_bonus). This small label prevents accidental merging.
What does the supplied Python program print?
- A7 then 7
- B10 then 12
- C10 then 7
- DIt always raises an error
Explain the difference between the global score and the local score in the supplied program.
Refer to where each can be accessed and which assignment changes.
Students type their answer here.
Remove unnecessary global state
Refactor the function so it takes the current score and bonus as parameters and returns the updated score. It must not use a global declaration.
def updated_score(current, bonus):
passA different version stores tax_rate = 0.2 locally inside final_price(). Rewrite the short design so tax_rate is a global variable that the function reads, then state one benefit and one drawback of that change.
Show the global declaration/assignment and the function use. Keep the comparison balanced: wider access may avoid repeated parameters, but creates a hidden dependency and may keep data alive for longer.
Students type their answer here.
Explain two drawbacks of excessive global variables in a larger program.
For each, give a mechanism and its consequence for development or execution.
Students type their answer here.
Checkpoint
Complete the scope explanation from memory. There is no answer bank, and correctness is withheld until teacher review.
Review your understanding
Before submitting, check that you can explain the main distinction in your own words, apply it in an unfamiliar context and justify the resulting behaviour or consequence.