第2个回答 2019-10-25
# 为校园歌咏比赛编写一个评分程序,
# 功能:当选手表演结束以后, 分别录入7位评委的成绩,然后求出去
# 掉一个最高分,去掉一个最低分以后的平均成绩,并作为选手的最后
# 得分。
# 最后输出:
# 最高分: 最低分:平均分。
def max(line):
maxNum = 0
for i in line:
if i >= maxNum:
maxNum = i
return maxNum
def min(line):
minNum = line[0]
for i in line:
if i <= minNum:
minNum = i
return minNum
def newLine(line):
maxScore = max(line)
minScore = min(line)
newLine = []
for i in line:
if i != maxScore and i != minScore:
newLine.append(i)
return newLine
def sum(newLine):
s = 0
for i in newLine:
s = s + i
return s
def higher(newLine):
h = 0
for i in newLine:
if i >= h:
h = i
return h
def lower(newLine):
l = newLine[0]
for i in newLine:
if i <= l:
l = i
return l
def avg(newLine):
l = len(newLine)
s = sum(newLine)
avg = s / l
return avg
if __name__ == '__main__':
score = [1, 3, 2, 4, 5, 7, 9]
print("去掉最高分%d" % max(score))
print("去掉最低分%d" % min(score))
new = newLine(score)
print("总分%d" % sum(new))
print("最高分%d" % higher(new))
print("最低分%d" % lower(new))
print("平均分%d" % avg(new))