编写程序,创建类MyMath,计算圆的周长和面积以及球的表面积和体积,并编写测试代码,结果均保留两位小数
时间: 2024-05-27 22:14:37 浏览: 19
class MyMath:
# 计算圆的周长
@staticmethod
def circle_circumference(radius: float) -> float:
return round(2 * 3.14 * radius, 2)
# 计算圆的面积
@staticmethod
def circle_area(radius: float) -> float:
return round(3.14 * radius ** 2, 2)
# 计算球的表面积
@staticmethod
def sphere_surface_area(radius: float) -> float:
return round(4 * 3.14 * radius ** 2, 2)
# 计算球的体积
@staticmethod
def sphere_volume(radius: float) -> float:
return round(4 / 3 * 3.14 * radius ** 3, 2)
# 测试代码
print("圆的周长:", MyMath.circle_circumference(3))
print("圆的面积:", MyMath.circle_area(3))
print("球的表面积:", MyMath.sphere_surface_area(3))
print("球的体积:", MyMath.sphere_volume(3))
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)