Python-面向对象类的应用
分别求 多个学生的 程序设计、数学、英语考试成绩的平均值。
class Student:
count = 0
program_sum = 0
math_sum = 0
English_sum = 0
def __init__( self , id , name , program_grade , math_grade , English_grade) :
self.id = id
self. name = name
self. program_grade = program_grade
self. math_grade = math_grade
self. English_grade = English_grade
Student.count += 1
Student.program_sum += program_grade
Student.math_sum += math_grade
Student.English_sum += English_grade
def average( self ):
print("学生个数=",Student.count)
print("程序设计成绩=",Student.program_sum / Student.count)
print("数学成绩=",Student.math_sum / Student.count)
print("英语成绩=",Student.English_sum / Student.count)
s1 = Student('1','zhangsan',100,100,100)
s2 = Student('2','lisi',50,50,50)
s3 = Student('3','wangwu',30,30,30)
s3.average()