我制作了一个程序来计算列表中的第二大数字。输入是一个被切成列表的字符串。这是代码
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))
Run Code Online (Sandbox Code Playgroud)
它对正数工作正常,但如果列表包含负数,我的程序无法产生正确的答案。
对于输入
-7 -7 -7 -7 -6
输出是
-6而不是-7
有什么办法可以改善吗?