Runner-up
Inputs
values is a list of 0 to 12 whole numbers, each from -20 to 20.
Your tasks
- Use a loop to find the largest number,
first. - Use a second loop to find the largest number that is smaller than
first. Call itsecond. - Complete
secondLargestso it returnssecond, or null when there are not two different numbers. Return it, do not print it.
Example
With values = [5, 9, 9, 2, 7], secondLargest returns 7.
Rules
- Repeated copies of the largest number do not count as the runner-up.
- Return null (None in Python) when there is no runner-up.
Test data
TEST DATA 1: values is [5, 9, 9, 2, 7]
TEST DATA 2: values is [4, 4, 4]
Practice focus
Put an if inside the loop to keep, skip or change items. Filtering, mapping and comparing neighbours show up in nearly every array question.