2015-09-23 5902 views
-2

这就是我所拥有的。我需要打印的面积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 
+3

很少有评论1)修正你的函数的缩进,这是Python,缩进问题2)你在哪里调用你的函数来计算表面积? – paisanco

+0

请添加更具体的问题。你有什么尝试?什么是工作,什么不是? –

+0

打印功能不能正常工作...我有: –

回答

0

这里是你会怎么做:

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) 

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

+0

在打印功能上得到一个错误...这就是我在某处出错的地方。 –

+0

@tommcbride:如果您使用Python 3或更高版本,请使用print(compute_surface_area_cylindar(radius,height))' – wallyk

0
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))