I met that problem before while studying the OOP and lack experience for sure. Surfed through a lot of stackoverflow pages but somehow all suggestions do not help. Please, refer me to the appropriate resources or give some hint if possible. Thanks in advance!
class Student:
students = []
def __init__(self, name, money):
self.name = name
self.money = money
self.students.append(self)
@classmethod
def mostMoney(cls):
all_money = [elt.money for elt in cls.students]
if all(element == all_money[0] for element in all_money) == True:
return cls.students
else:
for student in cls.students:
max_money = student.money
current_name = student.name
if student.money >= max(all_money):
return max_money, current_name
else:
continue
student_1 = Student('Stas', 800)
student_2 = Student('Yarik', 800)
student_3 = Student('Kris', 800)
print(Student.mostMoney())
The idea to return all students if they have equal value in money. Here is the return I get.
[<__main__.Student object at 0x7f7ae679e130>, <__main__.Student object at 0x7f7ae66c2070>, <__main__.Student object at 0x7f7ae66c22e0>]