Python 3.x 我不熟悉编码,如果我的问题很愚蠢,请原谅,但我可以知道如何找到每个学生的考试总分吗?
正如你所看到的,我在获取平均值时遇到了一个问题,因为总数只取最后的测试分数,而不取总数你需要存储分数:Python 3.x 我不熟悉编码,如果我的问题很愚蠢,请原谅,但我可以知道如何找到每个学生的考试总分吗?,python-3.x,int,nested-loops,Python 3.x,Int,Nested Loops,正如你所看到的,我在获取平均值时遇到了一个问题,因为总数只取最后的测试分数,而不取总数你需要存储分数: 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))
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)))
而是将1添加到所有输出或更改范围以迭代
删除不必要的while循环
i=i + 1
0值的for循环自动结束
while tests>0:
break