while True:
try:
n=int(input('请输入评委人数'))
if n>=5:
print('当前评委人数为%s'%n)
break
else:
print('评委少于5人')
continue
except:
print('错误')
print(n)
scores=[]
for i in range(n):
while True:
try:
score = float(input('请输入第{0}个评委的分数:'.format(i+1)))
score = float(score)
assert 0<=score<=100
break
scores.append(score)
except:
print('分数错误')
qyh = max(scores)
wyj = min(scores)
scores.remove(qyh)
scores.remove(wyj)
finalScore = round(sum(scores)/len(scores,2))
formatter = '去掉一个最高分{0}\n取掉一个最低分{1}\n最后得分{2}'
print(formatter.format(qyh,wyj,finalScore))
给你修改了一下,望采纳!谢谢
while True:
try:
n=int(input('请输入评委人数'))
if n>=5:
print('当前评委人数为%s'%n)
break
else:
print('评委少于5人')
continue
except:
print('错误')
print(n)
scores=[]
for i in range(n):
#while True:
try:
score = float(input('请输入第{0}个评委的分数:'.format(i+1)))
score = float(score)
assert 0<=score<=100
#break
scores.append(score)
except:
print('分数错误')
qyh = max(scores)
wyj = min(scores)
scores.remove(qyh)
scores.remove(wyj)
finalScore = round(sum(scores)/len(scores))
formatter = '去掉一个最高分{0}\n取掉一个最低分{1}\n最后得分{2}'
print(formatter.format(qyh,wyj,finalScore))