.写一个Circle类,该类可以计算出圆的面积和周长.并写一个测试类TestCircle,生成半径为1和10的两个对象,并分别输出这两个对象的周长和面积
时间: 2023-05-21 17:02:23 浏览: 71
好的,下面是Circle类和TestCircle类的代码:
```python
class Circle:
def __init__(self, radius):
self.radius = radius
def get_area(self):
return 3.14 * self.radius ** 2
def get_circumference(self):
return 2 * 3.14 * self.radius
class TestCircle:
def __init__(self):
self.circle1 = Circle(1)
self.circle2 = Circle(10)
def print_info(self):
print("半径为1的圆的周长为:", self.circle1.get_circumference())
print("半径为1的圆的面积为:", self.circle1.get_area())
print("半径为10的圆的周长为:", self.circle2.get_circumference())
print("半径为10的圆的面积为:", self.circle2.get_area())
test_circle = TestCircle()
test_circle.print_info()
```
输出结果为:
```
半径为1的圆的周长为: 6.28
半径为1的圆的面积为: 3.14
半径为10的圆的周长为: 62.800000000000004
半径为10的圆的面积为: 314.0
```
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/x-java](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)