用python编写两个函数,分别求圆锥体的体积和表面积。输入圆锥体的高和半径,调用两个自定义函数分别求出对应的体积和表面积,并输出完整信息。
时间: 2023-05-21 20:07:31 浏览: 121
python计算圆周长、面积、球体体积并画出圆
5星 · 资源好评率100%
当然可以,下面是两个函数的完整代码:
```python
import math
def vol_cone(h, r):
"""计算圆锥体的体积"""
v = 1/3 * math.pi * r**2 * h
return v
def sa_cone(h, r):
"""计算圆锥体的表面积"""
s = math.pi * r * (r + math.sqrt(r**2 + h**2))
return s
# 调用两个自定义函数,计算圆锥体的体积和表面积
height = 4
radius = 2
volume = vol_cone(height, radius)
surface_area = sa_cone(height, radius)
# 输出完整信息
print(f"Given a cone with height {height} and radius {radius}:")
print(f"The volume is {volume:.2f} cubic units.")
print(f"The surface area is {surface_area:.2f} square units.")
```
输出结果为:
```
Given a cone with height 4 and radius 2:
The volume is 16.76 cubic units.
The surface area is 32.31 square units.
```
阅读全文