在 Python 程式中求圓柱的周長


在本文中,我們將瞭解如何解決以下問題陳述 −

問題陳述

輸入直徑和高度,求圓柱的周長。

周長就是圓柱的側面檢視,即一個矩形。

因此 周長= 2 * ( h + d )

其中 d 是圓柱的直徑

h 是圓柱的高度

現在讓我們看看實現方法

示例

線上示例

# Function to calculate the perimeter of a cylinder
def perimeter( diameter, height ) :
   return 2 * ( diameter + height )
# main
diameter = 5 ;
height = 10 ;
print ("Perimeter = ",perimeter(diameter, height))

輸出

('Perimeter =', 30)

所有變數和函式均在全域性框架中宣告,如下圖所示。

結論

在本文中,我們學習瞭如何使用 Python 3.x 或更早版本求圓柱的周長。

更新於: 2019 年 9 月 26 日

316 次瀏覽

啟動你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.