Python:计算圆柱体的表面积

Python:计算圆柱体的表面积,python,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("He

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

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

以下是您将如何做到这一点:

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)

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

几点注释1)修复函数上的缩进,这是Python,缩进问题2)在哪里调用函数来计算表面积?请添加更具体的问题。你试过什么?什么在工作,什么不在工作?打印函数不工作…我有:打印计算表面面积圆柱(半径,高度)你得到了什么错误?打印函数出错…这就是我出错的地方。@tommcbride:如果你使用的是Python 3或更高版本,请使用
打印(计算表面面积圆柱(半径,高度))
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))