1. 定义学生类,包括学号、姓名、性别、成绩,并将课程成绩全部初始化为0; 2. 定义类成员函数,完成修改学生的信息,统计所有学生课程的平均成绩、最高分和最低分; 3. 输出所有学生信息; 4. 通过输入学生学号或姓名查询某学生的信息。
时间: 2023-05-26 14:07:13 浏览: 102
学生成绩管理系统 系统功能基本要求 学生信息,学号、姓名、性别、专业、年级等
1.定义学生类,包括学号、姓名、性别、成绩,并将课程成绩全部初始化为0:
class Student:
def __init__(self, number, name, gender):
self.number = number
self.name = name
self.gender = gender
self.courses = {'math': 0, 'english': 0, 'history': 0, 'science': 0}
2.定义类成员函数,完成修改学生的信息,统计所有学生课程的平均成绩、最高分和最低分:
class Student:
def __init__(self, number, name, gender):
self.number = number
self.name = name
self.gender = gender
self.courses = {'math': 0, 'english': 0, 'history': 0, 'science': 0}
def update_score(self, course, score):
self.courses[course] = score
def get_average_score(self):
total_score = 0
for score in self.courses.values():
total_score += score
average_score = total_score / len(self.courses)
return average_score
def get_max_score(self):
max_score = max(self.courses.values())
return max_score
def get_min_score(self):
min_score = min(self.courses.values())
return min_score
3.输出所有学生信息:
students = [Student('001', 'Tom', 'male'), Student('002', 'Jack', 'male'), Student('003', 'Lucy', 'female')]
for student in students:
print('Student number:', student.number)
print('Student name:', student.name)
print('Student gender:', student.gender)
print('Student scores:')
for course, score in student.courses.items():
print(course, ':', score)
print('--------------------------------')
4.通过输入学生学号或姓名查询某学生的信息:
def search_student(students, input):
for student in students:
if input == student.number or input == student.name:
print('Student number:', student.number)
print('Student name:', student.name)
print('Student gender:', student.gender)
print('Student scores:')
for course, score in student.courses.items():
print(course, ':', score)
return
print('Student not found')
input = input('Please enter the student number or name:')
search_student(students, input)
阅读全文