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-loop自动结束。