python趣味編程:歌星大獎賽


題目:歌星大獎賽
內容:在歌星大獎賽中,有10個評委為參賽的選手打分,分數為1到100分。選
手最后得分為去掉一個最高分和一個最低分后,其余8個分數的平均值。
問題分析和算法設計:
問題算法比較簡單,主要是用到兩個知識點,一是判斷最大值和最小值,二是
計算平均值。

代碼如下:

##@小五義 http://www.cnblogs.com/xiaowuyi
'''
題目:歌星大獎賽
內容:在歌星大獎賽中,有10個評委為參賽的選手打分,分數為1到100分。選
手最后得分為去掉一個最高分和一個最低分后,其余8個分數的平均值。
'''
def inputscore(num):
    i=True  #判斷輸入的成績是否合法
    while i:
        try:
            print '評委%d:'%num
            score=float(raw_input('請輸入成績(0-100):'))  
            if score>100 or score<0:
                print '輸入錯誤,請重新輸入'
                i=True
            else:
                i=False
        except:
            print '輸入錯誤,請重新輸入'
            i=True
    return score

if __name__=='__main__':
    sumscore=0  #求和
    maxscore=0  #記錄最大成績
    minscore=100  #記錄最小成績
    for i in range(10):
        intscore=inputscore(i+1)
        sumscore+=intscore
        if intscore>maxscore:
            maxscore=intscore
        elif intscore<minscore:
            minscore=intscore
    
    averagescore=(sumscore-maxscore-minscore)/8.0  #計算平均分
    print '去掉一個最高分%f,去掉一個最低分%f,本選手的最后得分是%f'%(maxscore,minscore,averagescore)
    
        
        

轉載請注明:@小五義  http://www.cnblogs.com/xiaowuyi


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM