Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from dataclasses import dataclass
- from pprint import pprint
- @dataclass
- class Student:
- name: str
- surname: str
- math: int
- physics: int
- informatics: int
- def rate(self):
- return (self.math + self.physics + self.informatics) / 3.0
- def read_student(line: str) -> Student:
- fields = line.split(" ")
- return Student(
- name=fields[1],
- surname=fields[0],
- math=int(fields[2]),
- physics=int(fields[3]),
- informatics=int(fields[4])
- )
- def main():
- students = []
- with open("students.txt", 'r', encoding='UTF-8') as students_file:
- lines_count = int(students_file.readline())
- for student in students_file:
- students.append(read_student(student))
- students.sort(key=lambda student: student.rate())
- pprint(students)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement