阅读主函数代码,完成Shape类、Circle类、Rectangle类的定义
时间: 2023-12-12 20:03:00 浏览: 101
Shape类定义:
```python
class Shape:
def __init__(self, color):
self.color = color
def get_area(self):
pass
def get_perimeter(self):
pass
```
Circle类定义:
```python
import math
class Circle(Shape):
def __init__(self, color, radius):
super().__init__(color)
self.radius = radius
def get_area(self):
return math.pi * self.radius ** 2
def get_perimeter(self):
return 2 * math.pi * self.radius
```
Rectangle类定义:
```python
class Rectangle(Shape):
def __init__(self, color, width, height):
super().__init__(color)
self.width = width
self.height = height
def get_area(self):
return self.width * self.height
def get_perimeter(self):
return 2 * (self.width + self.height)
```
阅读全文