排序模块只从显示的第一位数字排序,而不是从最小到最大

所以基本上这段代码是关于五项考试分数,去掉最低分,然后计算最高四分的平均值。

a = input("Enter test 1: ")
while int(a) < 0 or int(a) > 100:
    a = input("Please try again: ")
b = input("Enter test 2: ")
while int(b) < 0 or int(b) > 100:
    b = input("Please try again: ")
c = input("Enter test 3: ")
while int(c) < 0 or int(c) > 100:
    c = input("Please try again: ")
d = input("Enter test 4: ")
while int(d) < 0 or int(d) > 100:
    d = input("Please try again: ")
e = input("Enter test 5: ")
while int(e) < 0 or int(e) > 100:
    e = input("Please try again: ")

score = [a,b,c,d,e]

def findLowest(a):
    a.sort()
    return a[0]

def calcAverage(a):
    a.reverse()
    a.pop()
    t = 0
    for i in a:
        t = t + int(i)
    
    m = t/len(a)
    
    return int(m)

low = findLowest(score)
avg = calcAverage(score)

print("After Dropping the lowest test score ("+low+"),the average of the tests is a "+str(avg)+"!")

然而,我的问题是,当我输入 100 和其他一些其他两位数值时,sort() 命令会自动假定 100 是最小的,从而破坏了整个代码。我尝试了这个,10 是最高的,其他分数是一位数的值,它显示了同样的问题。我想知道我是否做错了什么。

zhtang0526 回答:排序模块只从显示的第一位数字排序,而不是从最小到最大

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/74824.html

大家都在问