logo

AQA A-Level Computer Science practice

Study the Python code below. Identify the global and local variables, then explain where each can be accessed. score = 5 def show_score(): message = "Current score" print(message) print(score) show_score() print(score)

Try the question first, then check the answer and practise the same topic again.

At a glance

Question

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

Study the Python code below. Identify the global and local variables, then explain where each can be accessed. score = 5 def show_score(): message = "Current score" print(message) print(score) show_score() print(score).

Answer and explanation

Concise answer

score is a global variable because it is defined outside show_score.

Why this is correct

The position where each variable is defined determines its scope in this example. score is defined outside the function, so it has wider access. message is defined inside the function, so its access is limited to that function.

Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions