Skip to content
Open
Changes from 2 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
56 changes: 55 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -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]

@classmethod
def write_groups_information(cls, groups) -> 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

@classmethod
def write_students_information(cls, students: List[Student]) -> int:
with open("students.pickle", "wb") as f:
pickle.dump(students, f)

return len(students)

@classmethod
def read_groups_information(cls, groups) -> List[str]:
with open("groups.pickle", "rb") as f:
pickle.load(f)
names = list({g.specialty.name for g in groups})
return names

@classmethod
def read_students_information(cls, students: List[Student]) -> int:
with open("students.pickle", "rb") as f:
pickle.load(f)
return students
Loading