0

i having problem with operator overloading question

pls anyone let me know about this is correct def __add__(self,other): #add method for adding two Shape objects if isinstance(other,Shape): new_width=self.width + other.width new_height=self.height + other.height return Shape(new_width,new_height) else: raise TypeError("Unsupported operand type for +:{}".format (type(other)) def __gt__(self,other): #Greter-than method for comparing the areas of two shape objects if isinstance(other, Shape): return self.area()> other.area() else: raise TypeError("Unsupported operand type for >:{}".format (type(other)) for me is correct they asking having invalid syntax with def __gt__ pls

24th Mar 2024, 12:05 AM
Muhammad Haris Khan
3 Respostas
+ 4
Muhammad Haris Khan the TypeError in both methods are missing a closing parenthesis. raise TypeError("Unsupported operand type for +:{}".format (type(other))) <--- THIS
24th Mar 2024, 1:19 AM
Bob_Li
Bob_Li - avatar
+ 1
yes is correct thanks Bob_Li for helping me
24th Mar 2024, 2:12 AM
Muhammad Haris Khan
0
i think maybe def __gt__(self.other): is the invalid syntax now what should i do to get correct code
24th Mar 2024, 12:48 AM
Muhammad Haris Khan