logo

AQA A-Level Computer Science practice

Write a Python 3 subroutine called calculate_area that declares a local variable called area, assigns it the product of length and width, and returns area. Then explain why area is a local variable.

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

Write a Python 3 subroutine called calculate_area that declares a local variable called area, assigns it the product of length and width, and returns area. Then explain why area is a local variable.

Answer and explanation

Concise answer

def calculate_area(length, width): area = length * width return area

Why this is correct

The assignment area = length * width declares and assigns the variable within the subroutine. Its scope is limited to calculate_area, and it does not remain available as a local variable after the subroutine finishes.

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