Intermediate python course practice 22.2, (Shape factory) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

25th Sep 2022, 5:21 PM
Diksha Sharma
Diksha Sharma - avatar
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.
25th Sep 2022, 6:12 PM
Tibor Santa
Tibor Santa - avatar
0
Thankyou
26th Sep 2022, 6:21 AM
Diksha Sharma
Diksha Sharma - avatar