总分最高的学生姓名和各科成绩

题目

代码

class Student:
    def __init__(self, sname, mscore, cscore, escore):
        self.sname = sname
        self.mscore = mscore
        self.cscore = cscore
        self.escore = escore
    def total(self):
        return  self.mscore + self.cscore + self.escore 

def FindMaxScoreStudent(sname,mscore,cscore,escore):
    students = []
    total = []
    for i in range(len(sname)):
        students.append( Student(sname[i], mscore[i], cscore[i], escore[i]))
        total.append(students[i].total())
    student = students[total.index(max(total))]
    return student

sname = list(map(str,input("Enter sname:\n").split( )))
mscore = list(map(int,input("Enter mscore:\n").split( )))
cscore = list(map(int,input("Enter cscore:\n").split( )))
escore = list(map(int,input("Enter escore:\n").split( )))
student =  FindMaxScoreStudent(sname,mscore,cscore,escore)
print(student.sname + ' ' + str(student.mscore) + ' ' + str(student.cscore) + ' ' + str(student.escore)) 

输入

Enter sname:
jack tom
Enter mscore:
95 84
Enter cscore:
90 75
Enter escore:
85 90

输出

jack 95 90 85

posted @ 2020-05-05 14:38  sinlearn  阅读(248)  评论(0编辑  收藏  举报