7-7 jmu-python-异常-学生成绩处理中级版 (15分)

7-7 jmu-python-异常-学生成绩处理中级版 (15分)_第1张图片

n = int(input())
cnt = n
s = 0
judge = True
while cnt > 0:
    try:
        x = input()
        x = int(x)
        s += x
        cnt -= 1
    except:
        print('Error for data {}! Reinput'.format(x))
        judge = False
        continue
if judge:
    print('All OK')
print('avg grade = {:.2f}'.format(s/n))

 

你可能感兴趣的:(PTA作业,python)