Python:计算圆柱体的表面积

2024-09-30 14:25:37 发布

您现在位置:Python中文网/ 问答频道 /正文

这就是我所拥有的。我需要打印表面积

def compute_surface_area_cylindar(radius, height):
    surface_area = 2 * math.pi * r * h + 2 * math.pi * math.pow(r, 2)
    return surface_area

radius = input("Radius of circle:")
radius = int(radius)
r = radius
height = input("Height of the cylinder:")
height = int(height)
h = height

Tags: ofinputreturndefpiareamathsurface
2条回答
import math

def compute_surface_area_cylindar(radius, height):
    surface_area = 2 * math.pi * radius * height + 2 * math.pi * math.pow(radius, 2)
    return surface_area


radius = int(input("Radius of circle:"))
#take this out "radius = int(radius)" and you save a line
#take this out an you save a line "r = radius"
height = int(input("Height of the cylinder:"))
# take this out and you save a line "height = int(height) "
#h = height
print(compute_surface_area_cylindar(radius,height))

以下是您的操作方法:

import math # You forgot this

def compute_surface_area_cylindar(radius, height):
    surface_area = 2 * math.pi * r * h + 2 * math.pi * math.pow(r, 2)
return surface_area

radius = input("Radius of circle:")
radius = int(radius)
r = radius
height = input("Height of the cylinder:")
height = int(height)
h = height

print compute_surface_area_cylindar(radius,height)

以上代码将根据半径和高度输出圆柱体的表面积,假设上面的公式是正确的。在

相关问题 更多 >