评委打分:
题目要求:
十个10评委打分,去掉一个最高分,去掉一个最低分,求平均分。
简单的版本不要求实现控制台输入分数
数据(直接写在程序里):
list=[90,89,91,92, 93,96,87,89, 90,91];
加分项:
实现分数从控制台输入
解题:
if __name__ == '__main__':
scores = [90, 89, 91, 92, 93, 96, 87, 89, 90, 91]
scores.remove(max(scores))
scores.remove(min(scores))
mean = sum(scores) / 8
print(mean)
没有max和min:手动找max和min
if __name__ == '__main__':
scores = [90, 89, 91, 92, 93, 96, 87, 89, 90, 91]
maxScore = scores[1]
minScore = scores[1]
for item in scores:
if item > maxScore:
maxScore = item
if item < minScore:
minScore = item
scores.remove(maxScore)
scores.remove(minScore)
mean = sum(scores) / 8
print(mean)
sorted来实现
if __name__ == '__main__':
scores = [90, 89, 91, 92, 93, 96, 87, 89, 90, 91]
newScore = sorted(scores)
newScore.pop(0)
newScore.pop(8)
mean = sum(newScore) / 8
print(mean)
实现分数从控制台输入:
if __name__ == '__main__':
scores = []
for n in range (1, 11):
print("请输入第%d个评委的打分:"%(n))
score = int(input())
scores.append(score)
print(scores)
scores.remove(max(scores))
scores.remove(min(scores))
mean = sum(scores) / 8
print(mean)