大佬,打印出平均分,最高,最低分的语句怎么写呀?如图!
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
# 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