python - 找到最低的测试分数和两个高分的平均值

标签 python average display

我在作业中解决了所有其他问题,但我卡在了最后一步,这需要我找到最低的测试分数,然后显示最高的两个测试分数的平均值,并显示最低的测试分数。我知道我需要在“def findAndReturnLowest”下添加一个 if/elif/else 函数,但我发现了错误。这是我应该做的屏幕截图 enter image description here

这是我的代码

def main():
    score1 = 0.0
    score2 = 0.0
    score3 = 0.0

    score1 = getTestScore()
    score2 = getTestScore()
    score3 = getTestScore()

    calcAvgAndDisplayResults(score1, score2, score3)

def calcAvgAndDisplayResults(s1, s2, s3):
    lowest = 0.0
    average = 0.0
    lowest = findAndReturnLowest(s1, s2, s3)
def findAndReturnLowest(s1, s2, s3):


    average = (s1+s2+s3-lowest)/2
    print("Average = ", average)

def getTestScore():
    test = 0.0
    test=float(input("Enter a test score between 0 and 100: "))
    return test

# start of program
main()

最佳答案

使用嵌套的if:

def findAndReturnLowest(s1, s2, s3):
    if s1 > s3 and s2 > s3:
        return s3

    else:
        return s2 if s1 > s2 else s1

关于python - 找到最低的测试分数和两个高分的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55369212/

相关文章:

html - 根据屏幕大小将元素列表分成 2 到 3 列

python - 从字符串中删除冗余符号

python - 如何按常见项目对元组进行分组并查找每组的平均值

mysql - 购买表的 AVG 间隔长度

php - 如何选择过去六个月的销售值?

html - 垂直对齐行内 block 元素

python - 如何从 Python 中的不同类访问使用一个类创建的对象

python:图像的带通滤波器

python - 将数组转换为 python 列表列表

html - 调整窗口大小时将元素推离屏幕而不是挤压它们