class Student:
students: list["Student"] = []
def __init__(self, first_name: str, last_name: str, total_mark: int) -> None:
self.first_name = first_name
self.last_name = last_name
self.total_mark = total_mark
self.students.append(self)
def __repr__(self) -> str:
return f'Student {self.first_name} {self.last_name} has mark: {self.total_mark}'
class Party:
@staticmethod
def is_student_invited(student: Student):
return 500 > student.total_mark > 250
@staticmethod
def notify_student_failed_course (students: list) -> list [Student]:
for student in students:
if 250 > student.total_mark or student.total_mark > 500:
print(student.total_mark)
def get_invited_students(self, students: list) -> list[Student]:
invited_student_list = []
for student in self.students:
if self.is_student_invited(student) == True:
invited_student_list.append(student)
else:
self.notify_student_failed_course(student)
student1 = Student('Tom', 'Brown', 400)
student2 = Student('Kate', 'Bel', 350)
student3 = Student('Anton', 'Dee', 43)
student4 = Student('Mike', 'pike', 345)
print(Party.get_invited_students(Student.students))
I need to create a method get_invited_students, that returns list of students, that is invited to a party(with total mark 250 - 500) using method is_student_invited(student). When I launch this code, i see TypeError: Party.get_invited_students() missing 1 required positional argument: 'students'. What I did wrong ?
CodePudding user response:
Change Party class as below
class Party:
@staticmethod
def is_student_invited(student: Student):
return 500 > student.total_mark > 250
@staticmethod
def notify_student_failed_course (student: Student):
if 250 > student.total_mark or student.total_mark > 500:
print(student.total_mark)
@staticmethod
def get_invited_students(students: list) -> list[Student]:
invited_student_list = []
for student in students:
if Party.is_student_invited(student) == True:
invited_student_list.append(student)
else:
Party.notify_student_failed_course(student)
return invited_student_list
CodePudding user response:
You need to init class before call function
party = Party()
print(party.get_invited_students(Student.students))