class Student:
def __init__(self, student_index, surname_name='Иванов Иван', group_number='5A', grades=None):
self.index = student_index
self.surname_name = surname_name
self.group_number = group_number
self.grades = grades
def print_info(self):
print(f'Фамилия: {self.surname_name}\nНомер группы: {self.group_number}\nУспеваемость: {self.grades}')
class Faculty:
def __init__(self, number):
self.students = [Student(index) for index in range(1, number + 1)]
def fill_data(self):
print('Заполните данные студентов.')
for index, student in enumerate(self.students):
surname_and_name = input(f'Введите Фамилию и Имя {index + 1}-го студента: ')
group_number = input('Введите номер группы студента: ')
student_grades = []
for grade_index in range(5):
while True:
try:
grade = int(input(f'Введите {grade_index+1}-ю оценку студента: '))
student_grades.append(grade)
except ValueError:
print('Введено некорректное значение. Попробуйте ещё раз…')
continue
else:
break
print()
student.surname_name = surname_and_name
student.group_number = group_number
student.grades = student_grades
def sort_by_average(self):
students_range = len(self.students)
for number in range(students_range - 1):
for index in range(students_range - number - 1):
curr_average_grade = sum(self.students[index].grades) / len(self.students[index].grades)
next_average_grade = sum(self.students[index + 1].grades) / len(self.students[index + 1].grades)
if curr_average_grade > next_average_grade:
self.students[index], self.students[index + 1] = self.students[index + 1], self.students[index]
def print_info(self):
for student in self.students:
student.print_info()
add_students = Faculty(5)
add_students.fill_data()
add_students.sort_by_average()
add_students.print_info()