Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read a line of integers and print the second largest distinct value.
The catch is "distinct": if the biggest number appears twice, the second largest is still the next different number down.
Input. One line: integers separated by spaces (at least two distinct values).
Output. One integer: the second largest distinct value.
Examples
Input
4 1 7 7 3
Output
4
Input
10 20 30
Output
20
Hint
- set(nums) drops duplicates.
- sorted(...) puts them ascending, so index -2 is the second largest.
Show correct code
Peek only after you have tried. You can still Check your own version.
nums = list(map(int, input().split()))
print(sorted(set(nums))[-2])
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.