Second Largest
beginnerUp next
Up next
Output will appear here...
The starter code reads a line of integers into a list called numbers. Print the second-largest distinct value. If the largest value appears more than once, it still only counts once.
For the input 4 9 2 7, a correct solution prints 7. For 10 10 5, it prints 5.
The input always contains at least two different values.
Tip
One approach: find the largest value with max(), remove every copy of it from the list, then take max() again. A while loop with .remove() works well for removing all copies.
No comments yet. Start the discussion.