首页 > 其他 > 详细

赛场统分

时间:2016-07-11 01:27:44      阅读:301      评论:0      收藏:0      [点我收藏+]

程序地址:http://www.cheemoedu.com/exercise/7


问题描述:

在编程竞赛中,有10个评委为参赛的选手打分,分数为0~100分。选手最后得分为:去掉一个最高分和一个最低分后其余8个分数的平均值。
请编写一个程序实现。


我的代码:

scores=[]
i=1
while i <= 4:
    score=int(raw_input("please input the score: "))
    scores.append(score)
    i+=1
scores.remove(max(scores))
scores.remove(min(scores))
fscore=sum(scores)/2
print "The final score is:",fscore


思路就不用说了,很简单的一道题,只不过为了省事仅设置了四个分数,而且没有对用户输入的数进行类型判断,想要的话可以自己加上,这里就不加了;


示例代码(更改后的,原代码的变量命名上有点问题):

import random
score = [random.randint(1,100) for x in xrange(10)]
print score
score.remove(max(score))
score.remove(min(score))
result = sum(score) / len(score)
print result


赛场统分

原文:http://jmbzs.blog.51cto.com/9449309/1814438

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!