weixin_47712582 2020-05-11 11:16 采纳率: 100%
浏览 100
已采纳

求助一道python入门题的打印语句怎么写

大佬,打印出平均分,最高,最低分的语句怎么写呀?如图!图片说明

class students:
    def __init__(self,name,hao,math,english,computer):
        self.name=name
        self.hao=hao
        self.math=math
        self.english=english
        self.computer=computer

    def score(self):
        score=self.math +self.english +self.computer
        return score
    def math(self):
        return self.math
    def english(self):
        return self.english
    def computer(self):
        return self.computer

class subject:
    def __init__(self,*students):
        self.list1=[i.math() for i in students]
        self.list2=[i.english() for i in students]
        self.list3=[i.conputer() for i in students]

    def ave(self):
        return "数学平均分{}英语平均分{}计算机平均分{}".format(sum(self.list1)/len(self.list1),sum(self.list2)/len(self.list2),sum(self.list3)/len(self.list3))

    def max(self):
        return"数学最高分{}英语最高分{}计算机最高分{}".format(max(self.list1),max(self.list2),max(self.list3))

    def min(self):
        return"数学最低分{}英语最低分{}计算机最低分{}".format(min(self.list1),min(self.list2),min(self.list3))

a=students('zhang',2000,91,96,93)
b=students('ming',2001,93,82,91)
c=students('chen',2002,86,84,93)

print("总分为:",a.score(),b.score(),c.score())
print
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-05-11 11:56
    关注

    问题解决的话,请点下采纳

    # encoding: utf-8
    
    
    class students:
        def __init__(self,name,hao,math2,english2,computer2):
            self.name=name
            self.hao=hao
            self.math1=math2
            self.english1=english2
            self.computer1=computer2
    
        def score(self):
            score=self.math1 +self.english1 +self.computer1
            return score
        def math(self):
            return self.math1
        def english(self):
            return self.english1
        def computer(self):
            return self.computer1
    
    class subject:
        def __init__(self,*students):
            l = list(students)
            self.list1=[i.math() for i in l]
            self.list2=[i.english() for i in l]
            self.list3=[i.computer() for i in l]
    
        def ave(self):
            return "数学平均分{}英语平均分{}计算机平均分{}".format(sum(self.list1)/len(self.list1),sum(self.list2)/len(self.list2),sum(self.list3)/len(self.list3))
    
        def max(self):
            return"数学最高分{}英语最高分{}计算机最高分{}".format(max(self.list1),max(self.list2),max(self.list3))
    
        def min(self):
            return"数学最低分{}英语最低分{}计算机最低分{}".format(min(self.list1),min(self.list2),min(self.list3))
    
    a=students('zhang',2000,91,96,93)
    b=students('ming',2001,93,82,91)
    c=students('chen',2002,86,84,93)
    
    print("总分为:{},{},{}".format(a.score(),b.score(),c.score()))
    stu = subject(a,b,c)
    
    print(stu.ave())
    print(stu.max())
    print(stu.min())
    
    

    总分为:280,266,263
    数学平均分90英语平均分87计算机平均分92
    数学最高分93英语最高分96计算机最高分93
    数学最低分86英语最低分82计算机最低分91

    问题解决的话,请点下采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示