0
Shape Factory - Intermediate Python
I’m having some trouble with this Code Coach. How do I fix the code? 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 Shape(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
2 ответов
+ 2
The dunder for adding up was supposedly __add__( ... ) you have written it add( ... ) - you missed the underscores.
Also, if the task asked you to print something out, you should. I don't see your code printing anything. I thought the task requires you to print area of the <result> object
+ 2
I added the underscores but didn’t need to print anything out for it to pass the test cases. Thank you very much :)