2015-09-23 5908 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))