Magic Method Practise - Minor to none Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

2nd Mar 2022, 8:16 AM
Didi
Didi - avatar
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
2nd Mar 2022, 8:37 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Problem solved, than you very much for the explanation.
2nd Mar 2022, 9:02 AM
Didi
Didi - avatar