我是编码新手,如果我的问题很愚蠢,请原谅我,但我可以知道如何找到每个学生的测试总分吗?

Im new to coding and pardon me if my question is dumb but may i know how do I find the total marks for the test for each student?

students=int(input('How many students do you have?'))
tests=int(input('How many test for your module?'))
for i in range(students):
    i=i + 1
    print('******* Student # {:0d} *******'.format(i))
    while tests>0:
        for t in range(tests):
            t=t+1
            total=int(input('test number {:0d}:'.format(t)))
        break
    average = total/tests
    print('the average for student # {:0.0f} is {:0.1f}'.format(i,average))

如你所见,我在获取平均值时遇到了问题,因为总分只包含最终测试分数,而不是总分

您需要存储标记:

total = 0
for t in range(tests):
    # note the += instead of the =
    # this adds the new mark instead of overwriting the old one
    total += int(input('test number {:0d}:'.format(t+1)))

一些小改进

不要在迭代时增加值

i=i + 1

改为将所有输出加 1 或更改范围以迭代


删除不必要的 while 循环

while tests>0:
    break

0 值的 for 循环自动结束