Using total_ordering decorator from func_tools, which only requires two implementations of the comparison methods.
fromfunctoolsimporttotal_ordering@total_orderingclassStudent:def__init__(self,name,fives,tens,twenties):self.name=nameself.fives=fivesself.tens=tensself.twenties=twenties# Added new property
self.money=self.fives*5+self.tens*10+self.twenties*20def__eq__(self,other):returnself.money==other.moneydef__lt__(self,other):returnself.money<other.moneyst1=Student('Héctor',1,7,3)st2=Student('Albert',5,4,3)st3=Student('Jordi',1,4,3)students=[st1,st2,st3]print(max(students).name)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My Python attempt :
Using total_ordering decorator from func_tools, which only requires two implementations of the comparison methods.