From 7f201377aa8ae1da297b99ca51feda1ab9c9106f Mon Sep 17 00:00:00 2001 From: vladiukdaria Date: Wed, 4 Feb 2026 15:49:47 +0100 Subject: [PATCH 1/3] dfs --- app/main.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..969224f0 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,60 @@ -# write your code here +import dataclasses +from datetime import datetime +from typing import List +import pickle + + +# ----------------- Dataclasses ----------------- +@dataclasses.dataclass +class Specialty: + name: str + number: int + + +@dataclasses.dataclass +class Student: + first_name: str + last_name: str + birth_date: datetime + average_mark: float + has_scholarship: bool + phone_number: str + address: str + + +@dataclasses.dataclass +class Group: + specialty: Specialty + course: int + students: List[Student] + + +# ----------------- Functions with pickle ----------------- +def write_groups_information(groups: List[Group]) -> int: + """Write groups to 'groups.pickle' and return max number of students in a group""" + with open("groups.pickle", "wb") as f: + pickle.dump(groups, f) + # Максимальное количество студентов в группе + return max(len(group.students) for group in groups) if groups else 0 + + +def write_students_information(students: List[Student]) -> int: + """Write all students to 'students.pickle' and return total number of students""" + with open("students.pickle", "wb") as f: + pickle.dump(students, f) + return len(students) + + +def read_groups_information() -> List[str]: + """Read groups from 'groups.pickle' and return unique specialty names""" + with open("groups.pickle", "rb") as f: + groups: List[Group] = pickle.load(f) + # Собираем уникальные названия специальностей + return list({group.specialty.name for group in groups}) + + +def read_students_information() -> List[Student]: + """Read students from 'students.pickle' and return list of Student objects""" + with open("students.pickle", "rb") as f: + students: List[Student] = pickle.load(f) + return students From 54d5e63d31290dd61547f164bee845b074b44f93 Mon Sep 17 00:00:00 2001 From: vladiukdaria Date: Wed, 4 Feb 2026 15:52:15 +0100 Subject: [PATCH 2/3] Update main.py, --- app/main.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/main.py b/app/main.py index 969224f0..5410010e 100644 --- a/app/main.py +++ b/app/main.py @@ -4,7 +4,6 @@ import pickle -# ----------------- Dataclasses ----------------- @dataclasses.dataclass class Specialty: name: str @@ -29,32 +28,29 @@ class Group: students: List[Student] -# ----------------- Functions with pickle ----------------- def write_groups_information(groups: List[Group]) -> int: - """Write groups to 'groups.pickle' and return max number of students in a group""" + """Сохраняет группы в 'groups.pickle', возвращает макс. число студентов""" with open("groups.pickle", "wb") as f: pickle.dump(groups, f) - # Максимальное количество студентов в группе - return max(len(group.students) for group in groups) if groups else 0 + return max(len(g.students) for g in groups) if groups else 0 def write_students_information(students: List[Student]) -> int: - """Write all students to 'students.pickle' and return total number of students""" + """Сохраняет студентов в 'students.pickle', возвращает количество""" with open("students.pickle", "wb") as f: pickle.dump(students, f) return len(students) def read_groups_information() -> List[str]: - """Read groups from 'groups.pickle' and return unique specialty names""" + """Читает группы из 'groups.pickle', возвращает уникальные названия специальностей""" with open("groups.pickle", "rb") as f: groups: List[Group] = pickle.load(f) - # Собираем уникальные названия специальностей - return list({group.specialty.name for group in groups}) + return list({g.specialty.name for g in groups}) def read_students_information() -> List[Student]: - """Read students from 'students.pickle' and return list of Student objects""" + """Читает студентов из 'students.pickle'""" with open("students.pickle", "rb") as f: students: List[Student] = pickle.load(f) return students From 3fe83282a9e9bd0ce13766acc0bf51bf47fe6f19 Mon Sep 17 00:00:00 2001 From: vladiukdaria Date: Wed, 4 Feb 2026 15:57:41 +0100 Subject: [PATCH 3/3] dsfd --- app/main.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 5410010e..e1f0b883 100644 --- a/app/main.py +++ b/app/main.py @@ -4,6 +4,7 @@ import pickle +# ----------------- Dataclasses ----------------- @dataclasses.dataclass class Specialty: name: str @@ -28,11 +29,15 @@ class Group: students: List[Student] +# ----------------- Functions ----------------- def write_groups_information(groups: List[Group]) -> int: """Сохраняет группы в 'groups.pickle', возвращает макс. число студентов""" with open("groups.pickle", "wb") as f: pickle.dump(groups, f) - return max(len(g.students) for g in groups) if groups else 0 + if not groups: + return 0 + max_students = max(len(g.students) for g in groups) + return max_students def write_students_information(students: List[Student]) -> int: @@ -43,10 +48,11 @@ def write_students_information(students: List[Student]) -> int: def read_groups_information() -> List[str]: - """Читает группы из 'groups.pickle', возвращает уникальные названия специальностей""" + """Читает группы из 'groups.pickle', возвращает уникальные специальности""" with open("groups.pickle", "rb") as f: groups: List[Group] = pickle.load(f) - return list({g.specialty.name for g in groups}) + specialty_names = {g.specialty.name for g in groups} + return list(specialty_names) def read_students_information() -> List[Student]: