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
  • explain drawbacks of relying heavily on global variables in a larger program

Inside: 6 explanation cells, 1 multiple-choice question, 1 fill-in-the-blanks cell, 2 written answers and 2 Python tasks. 15 marks, about 20 to 30 minutes.

Series: H446 2.2.1 · Programming techniques, part 5 of 14.

Shared by Coding PathwayVerified teacher

  • 12 cells
  • About 30 minutes
  • CC BY-SA 4.0
  • Shared 31 Aug 2026
  • Updated 3 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Variable scope

A live-stream overlay uses shared match state and temporary calculation values. Identical names can refer to different bindings in different scopes.

By the end, you will be able to

  • identify accessible local and global bindings
  • predict shadowing without assuming names are shared
  • explain side effects and developed global-state drawbacks
  • refactor hidden state into parameters and returns

Reactivate: function definition, parameter and return.

Worked scope reading

Read a name from the inside out. If a function assigns to score without selecting the global binding, that call creates or changes its local score. A same-named global can still exist outside. Returning the local result does not itself overwrite the global; the caller decides where to store the returned value.

Therefore a complete prediction tracks the global binding, the local binding for this call and the destination of the returned result separately.

Worked example
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

Global and local scope boundariesGlobal scope: score = 10Function-call scopelocal score = points + 2 = 7The matching name does not make the two bindings the same variable.

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.

Multiple choice1 mark

What does the supplied Python program print?

  • A7 then 7
  • B10 then 12
  • C10 then 7
  • DIt always raises an error
Written answer3 marks

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.

Coding task3 marks
def updated_score(current, bonus):
    pass
Written answer4 marks

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.

Fill in the blanks4 marks
A checkpoint gap 1 variable is accessible only within its declared subprogram or block. A checkpoint gap 2 variable can be accessed more widely. A local name can checkpoint gap 3 a global name, and unexpected shared-state changes are checkpoint gap 4.

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.