diff --git a/app/main.py b/app/main.py index fa56336e..abf46692 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,55 @@ -# write your code here +from dataclasses import dataclass +from datetime import datetime +from typing import List +import pickle + + +@dataclass +class Specialty: + name: str + number: int + + +@dataclass +class Student: + first_name: str + last_name: str + birth_date: datetime + average_mark: float + has_scholarship: bool + phone_number: int + address: str + + +@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) if groups else 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 = pickle.load(f) + names = list({g.specialty.name for g in groups}) + return names + + +def read_students_information() -> List[Student]: + with open("students.pickle", "rb") as f: + students = pickle.load(f) + return students