Understanding that inheritance makes code reusable, KiKi now defines a base class shape with private data as coordinates x and y, from which Rectangle and Circle classes derive, both of which have member functions GetArea() to find areas. The derived Rectangle class has data: the length and width of a Rectangle; The derived Circle class has data: the radius of the Circle. The Rectangle class, in turn, derives the Square class, which defines each class and tests it. Input three sets of data, namely, the length and width of the rectangle, the radius of the circle and the side length of the square, and output three sets of data, namely, the area of the rectangle, the circle and the square. PI is calculated as 3.14. Input description: Enter three lines, the first line is the length and width of the rectangle, the second line is the radius of the circle, and the third line is the side length of the square. Output description: three lines, respectively rectangle, circle, square area.Copy the code
class shape(): def __init__(self,x1,y1): self.x=x1 self.y=y1 class Rectangle(shape): def area(self): Y class circle(shape): def area(self): PI =3.14 return PI *self. X *self. X class square(Rectangle): def area(self): return self.x**2 x,y=list(map(int,input().split())) r=int(input()) b=int(input()) a=Rectangle(x, y) print(a.area()) a2=circle(r, r) s=a2.area() if s-int(s)==0: s=int(s) print(s) else: Print (round(s,2)) print(round(s,2)) print(round(s,2))Copy the code