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.
