I made a program to calculate the second largest number from a list. Input is a string that is sliced into a list. Here's the code
score1 = input()
score = score1.split()
score.sort()
maximum = max(score)
count = score.count(maximum)
for i in range(0,count):
score.pop()
print(max(score))
And it is working fine for positive numbers but if the list contains a negative number my program fails to produce the correct answer.
For Input
-7 -7 -7 -7 -6
Output is
-6
instead of-7
Any way to improve it?