logo

Question detail

Write a Python 3 subroutine called larger that accepts two numbers and returns the larger number. Then write a statement in the calling routine that stores the returned value in a variable called result. If the two numbers are equal, returning either number is acceptable.

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

Write a Python 3 subroutine called larger that accepts two numbers and returns the larger number. Then write a statement in the calling routine that stores the returned value in a variable called result. If the two numbers are equal, returning either number is acceptable.

Model answer

What a good answer should say

  • def larger(first, second): if first >= second: return first else: return second result = larger(12, 9)

Explanation

Why this works

The subroutine compares the two parameters. It returns first when first is greater than or equal to second; otherwise it returns second.

The calling routine uses larger(12, 9), receives 12, and stores that returned value in result.

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.