logo

AQA A-Level Computer Science practice

In this Python code, which variable is global? name = "Ava" def greet(): greeting = "Hello" print(greeting) Which variable is defined outside the function and can therefore be accessed from a wider part of the program?

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

At a glance

MCQ

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

In this Python code, which variable is global? name = "Ava" def greet(): greeting = "Hello" print(greeting) Which variable is defined outside the function and can therefore be accessed from a wider part of the program?.

  1. A.greeting
  2. B.greet
  3. C.name
  4. D.print

Answer and explanation

Concise answer

name

Why this is correct

name is defined outside greet, so it is the global variable in this example. greeting is defined inside the function and is local 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