Shape Factory - Intermediate Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

28th Nov 2022, 4:52 AM
Lashana Jegatheswaran
2 Answers
+ 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
28th Nov 2022, 5:17 AM
Ipang
+ 2
I added the underscores but didn’t need to print anything out for it to pass the test cases. Thank you very much :)
28th Nov 2022, 7:28 AM
Lashana Jegatheswaran