+ 2
Magic Method Practise - Minor to none Problem
Hi everyone, hope you can help me: In this code a result appears that I can't see why it appears: None You have to insert four numbers that result in a new shape. Area is calculated in one method and shape areas are compared in the other. I think it comes from the __gt__ method. Can you help how to do it right? https://code.sololearn.com/cpWMYNkVORl8/?ref=app https://code.sololearn.com/cpWMYNkVORl8/?ref=app
2 Answers
+ 6
You need to return from the __gt__ method not print in the method. All functions and methods in python will return None by default when no explicit value is returned. So, you print in the method is outputting True and then the method call is returning None to the print() where the __gt__ comparison is taking place, which then outputs it.
def __gt__(self, other):
return self.width*self.height > other.width*other.height
+ 3
Problem solved, than you very much for the explanation.