0
How to solve the identification error
class Shape: w = int(input()) h = int(input()) def __init__(self, w, h): self.width = w self.height = h def area(self): print(self.width*self.height) class Rectangle(Shape): def perimeter(self): return 2*(width+height) r = Rectangle(w, h) r.area() r.perimeter()
2 Respostas
+ 12
Amala Yakin ,
it is an *IndentationError*, which means the indent of code lines is not properly done.
> the 2 lines with *input()* should be outside the class
> class rectangle, line with return: ... 2 x self. ... is missing
> please use a proper indent of 4 spaces as suggested in the python pep-0008 *style guide for python code*
> the code also uses a mix of spaces and tabs as indentation that causes errors
+ 4
Also note that getting input is needed to be done for instanciating the object.
In the rectangle's perimeter function, you need tor every to the object properties via "self"