zoukankan      html  css  js  c++  java
  • 总分最高的学生姓名和各科成绩

    题目

    代码

    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:
    ").split( )))
    mscore = list(map(int,input("Enter mscore:
    ").split( )))
    cscore = list(map(int,input("Enter cscore:
    ").split( )))
    escore = list(map(int,input("Enter escore:
    ").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

  • 相关阅读:
    Day4-装饰器
    Day3-递归函数、高阶函数、匿名函数
    Day3-函数及作用域
    Day2-字符编码转换
    Day2-文件操作
    Day2-列表、字符串、字典、集合
    Day1-模块初识
    JavaScript 笔试题
    从JavaScript 数组去重谈性能优化
    prototype
  • 原文地址:https://www.cnblogs.com/sinlearn/p/12830693.html
Copyright © 2011-2022 走看看