Skip to content

Test - 2. students_and_mentor.py #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions 6.classes/students_and_mentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ def __init__(self, name, surname, gender):
self.finished_courses = []
self.courses_in_progress = []
self.grades = {}


def rate_lecturer(self, lecturer, course, grade):
if isinstance(lecturer, Lecturer) and course in lecturer.courses_attached and course in self.courses_in_progress:
if course in lecturer.grades:
lecturer.grades[course].append(grade)
else:
lecturer.grades[course] = [grade]
else:
return 'Ошибка: Лектор не прикреплен к курсу или студент не записан на курс.'


class Mentor:
def __init__(self, name, surname):
self.name = name
Expand All @@ -16,20 +26,55 @@ def __init__(self, name, surname):
def rate_hw(self, student, course, grade):
if isinstance(student, Student) and course in self.courses_attached and course in student.courses_in_progress:
if course in student.grades:
student.grades[course] += [grade]
student.grades[course].append(grade)
else:
student.grades[course] = [grade]
else:
return 'Ошибка'


class Lecturer(Mentor):
def __init__(self, name, surname):
super().__init__(name, surname)
self.grades = {} # Словарь для хранения оценок от студентов

def average_grade(self):
total_grades = 0
total_courses = 0
for grades in self.grades.values():
total_grades += sum(grades)
total_courses += len(grades)
return total_grades / total_courses if total_courses > 0 else 0


class Reviewer(Mentor):
def __init__(self, name, surname):
super().__init__(name, surname)

def rate_student(self, student, course, grade):
if isinstance(student, Student) and course in self.courses_attached and course in student.courses_in_progress:
if course in student.grades:
student.grades[course].append(grade)
else:
student.grades[course] = [grade]
else:
return 'Ошибка'

best_student = Student('Ruoy', 'Eman', 'your_gender')


# Пример использования классов
best_student = Student('Иван', 'Иванов', 'мужской')
best_student.courses_in_progress += ['Python']

cool_mentor = Mentor('Some', 'Buddy')
cool_mentor.courses_attached += ['Python']

cool_mentor.rate_hw(best_student, 'Python', 10)
cool_mentor.rate_hw(best_student, 'Python', 10)
cool_mentor.rate_hw(best_student, 'Python', 10)

print(best_student.grades)

cool_lecturer = Lecturer('Кирилл', 'Кириллов')
cool_lecturer.courses_attached += ['Python']

cool_reviewer = Reviewer('Александра', 'Александрова')
cool_reviewer.courses_attached += ['Python']

cool_reviewer.rate_student(best_student, 'Python', 3)

best_student.rate_lecturer(cool_lecturer, 'Python', 9)
best_student.rate_lecturer(cool_lecturer, 'Python', 10)

print(f'Оценки студента {best_student.name} {best_student.surname}: {best_student.grades}')
print(f'Оценки лектора {cool_lecturer.name} {cool_lecturer.surname}: {cool_lecturer.grades}')