python應用-輸入分數 輸出最高分數對應的名字


   

def main():
    names = ['劉備', '張飛', '曹操', '袁紹', '關羽', '趙雲', '周瑜']
    scores=[]
    num=0
    m=0
    for name in names:
        score = input('請輸入%s的成績: ' % name)
        scores.append(score)
    min_score, max_score = scores[0], scores[0]
    for i in range(1,len(scores)):
        if scores[i] > max_score:
            max_score = scores[i]
            num=max_score
            m=scores.index(max_score)
    print('最高分:', max_score)
    print('%s' % names[m])
    del names[m]
    del scores[m]
    print(names)
    print(scores)
    for i in range(1, len(scores)):
        if scores[i]==num:
            print ('%s'% names[i])
if __name__ == '__main__':
    main()

  結果: 請輸入劉備的成績: 88

                   請輸入張飛的成績: 78

                   請輸入曹操的成績: 85

                   請輸入袁紹的成績: 84

                   請輸入關羽的成績: 90

                   請輸入趙雲的成績: 84

                  請輸入周瑜的成績: 90

                  最高分: 90 關羽 ['劉備', '張飛', '曹操', '袁紹', '趙雲', '周瑜'] ['88', '78', '85', '84', '84', '90'] 周瑜


免責聲明!

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



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