计算圆的周长,圆面积,圆球表面积,圆球体积,圆柱体积,结果保留两位小数,每个结果后换行
时间: 2024-06-14 10:06:13 浏览: 130
以下是计算圆的周长、圆面积、圆球表面积、圆球体积和圆柱体积的Python代码示例:
```python
import math
def calculate_circle_properties(r):
circumference = 2 * math.pi * r
area = math.pi * r * r
return circumference, area
def calculate_sphere_properties(r):
surface_area = 4 * math.pi * r * r
volume = (4/3) * math.pi * r * r * r
return surface_area, volume
def calculate_cylinder_properties(r, h):
surface_area = 2 * math.pi * r * (r + h)
volume = math.pi * r * r * h
return surface_area, volume
r = float(input("请输入圆的半径: "))
h = float(input("请输入圆柱的高: "))
circumference, area = calculate_circle_properties(r)
surface_area_sphere, volume_sphere = calculate_sphere_properties(r)
surface_area_cylinder, volume_cylinder = calculate_cylinder_properties(r, h)
print("圆的周长为: {:.2f}".format(circumference))
print("圆的面积为: {:.2f}".format(area))
print("圆球表面积为: {:.2f}".format(surface_area_sphere))
print("圆球体积为: {:.2f}".format(volume_sphere))
print("圆柱体积为: {:.2f}".format(volume_cylinder))
```
阅读全文