python 设计一个学生类,这个学生类包括学生的学号、姓名和成绩,定义函数打印,可以打印学生的学号、姓名、成绩。计算这几名学生的成绩平均分,并进行显示
时间: 2023-12-16 15:09:02 浏览: 27
Python实现学生成绩管理系统
class Student:
def __init__(self, id, name, score):
self.id = id
self.name = name
self.score = score
def print_info(self):
print("学号:" + str(self.id))
print("姓名:" + self.name)
print("成绩:" + str(self.score))
students = [Student(1, "张三", 90), Student(2, "李四", 87), Student(3, "王五", 92), Student(4, "赵六", 85)]
sum_score = 0
for student in students:
student.print_info()
sum_score += student.score
average_score = sum_score / len(students)
print("平均成绩:" + str(average_score))
阅读全文