python使用列表来计算测试分数

2024-04-25 06:44:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一些关于如何完成这个项目的建议。可能有一种更干净、更流畅的方法来编写它,因此任何帮助都会受到欢迎。下面是说明:

创建一个程序,对课程的最终成绩进行分析。程序必须使用循环,并在添加时将每个年级追加到列表中。该程序要求用户输入10名学生的最终成绩(占总成绩的百分比)。程序随后将显示以下数据:

  • 全班最高的分数。
  • 全班最低的分数。
  • 全班平均分

这是我目前所拥有的。当我运行它时,我的平均值是错误的。我还认为有某种范围或索引函数来做循环部分?如果你想再加一分的话,我不想每次输入后都问你。

def main():
    scores = get_scores()
    total = get_total(scores)
    average = total/len(scores)
    my_list = [get_scores]
    print('The lowest score is: ', min(scores))
    print('The highest score is: ', max(scores))
    print('the average is: ', average)

def get_scores():
    test_scores = []
    again = 'y'
        while again == 'y':
        value = float(input('Enter score: '))
        test_scores.append(value)
        print('Do you want to enter another score?')
        again = input('y =yes, anything else = no: ')
        print()
    return test_scores

def get_total(value_list):
    total = 0.0
    for num in value_list:
        total += num
        return total

main()

谢谢你花时间看这个。欢迎任何帮助,我是编程新手,从你的反馈中学到了很多。

谢谢大家的反馈。我把你所有的建议都拼凑出来了。

def main():
    scores = get_scores()
    total = get_total(scores)
    average = total/len(scores)
    my_list = [get_scores]
    print('The lowest score is: ', min(scores))
    print('The highest score is: ', max(scores))
    print('the average is: ', average)

def get_scores():
    test_scores = []
    for scores in range(10):
        value = float(input('Enter score: '))
        test_scores.append(value)
    return test_scores

def get_total(value_list):
    total = 0.0
    for num in value_list:
        total += num
    return total

再次感谢大家的帮助和建议。这东西对我来说越来越难了,但我会继续努力的:)谢谢所有的o/

main()

Tags: thetest程序getreturnisvaluemain