From 1ef0d9d4dc117a182dcf8838a11545b3aa7f5632 Mon Sep 17 00:00:00 2001 From: Bogdan Bodenkov Date: Sat, 31 Jan 2026 20:14:31 +0200 Subject: [PATCH] Solution --- app/main.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..455080b0 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,51 @@ -# write your code here +import dataclasses +from datetime import datetime +import pickle + + +@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] + + +def write_groups_information(groups: list[Group]) -> int: + with open("groups.pickle", "wb") as f: + pickle.dump(groups, f) + return max((len(g.students) for g in groups), default=0) + + +def write_students_information(students: list[Student]) -> int: + with open("students.pickle", "wb") as f: + pickle.dump(students, f) + return len(students) + + +def read_groups_information() -> list[str]: + 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]: + with open("students.pickle", "rb") as f: + return pickle.load(f)