logo

Question detail

Explain the difference between a subroutine that returns a value and a subroutine that only displays a value. Include a Python 3 example showing how a returned value can be used in the calling routine.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

Explain the difference between a subroutine that returns a value and a subroutine that only displays a value. Include a Python 3 example showing how a returned value can be used in the calling routine.

Model answer

What a good answer should say

  • A subroutine that returns a value sends that value back to the calling routine, where it can be assigned to a variable or used in an expression.
  • For example: def square(number): return number * number answer = square(5) The returned value is 25, so answer stores 25.
  • Displaying a value is different because it only outputs information to the screen; it does not provide a value for the calling routine to use in a calculation.

Explanation

Why this works

The key distinction is that return transfers a value to the caller, while displaying a value only produces output. In the example, square(5) returns 25 and the calling routine stores that value in answer, allowing it to be used later.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.