0
Intermediate python course practice 22.2, (Shape factory)
class Shape: def __init__(self, w, h): self.width = w self.height = h def area(self): return self.width*self.height def add(self,other): return self.width+other.width,self.height+other.height def gt(self,other): return self.area()>other.area() w1 = int(input()) h1 = int(input()) w2 = int(input()) h2 = int(input()) s1 = Shape(w1, h1) s2 = Shape(w2, h2) result = s1 + s2 print(result.area()) print(s1 > s2) Why isn't my code working
2 Answers
+ 4
The magic methods are also known as "dunder" methods, which means double underscore. Their name must have __ before and after, just like __init__ they are: __add__ and __gt__
Your addition is currently returning a tuple of two numbers, but it should return a new Shape instance.
0
Thankyou