Skip to content
Open

dfs #1519

Changes from 1 commit
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
61 changes: 60 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -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
Loading