日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:計算圓柱體體積和表面積

創(chuàng)新互聯(lián)Python教程:

用例子編寫 Python 程序求圓柱體的體積和表面積。在我們進入 Python 程序?qū)ふ覉A柱體的體積和表面積之前,讓我們看看圓柱體的側(cè)面表面積、頂部或底部表面積和體積后面的定義和公式。

圓柱體的表面積

如果我們知道圓柱體的半徑和高度,那么我們可以使用公式計算圓柱體的表面積:

圓柱體的表面積= 2πr + 2πrh(其中 r 是半徑,h 是圓柱體的高度)。

圓柱體的體積

圓柱體內(nèi)部的空間量稱為體積。如果我們知道圓柱體的高度,那么我們可以用公式計算圓柱體的體積:

圓柱體的體積= πr h

圓柱體的側(cè)面面積= 2πrh

我們可以計算圓柱的頂面或底面面積= πr

尋找圓柱體體積和表面積的 Python 程序

這個 Python 程序允許用戶輸入半徑和高度的值。使用這些值,這個 Python 程序?qū)⒏鶕?jù)公式計算圓柱體的體積、圓柱體的表面積、圓柱體的橫向表面積、圓柱體的頂部或底部表面積。

# Python Program to find Volume & Surface Area of a Cylinder

PI = 3.14
radius = float(input('Please Enter the Radius of a Cylinder: '))
height = float(input('Please Enter the Height of a Cylinder: '))

sa = 2 * PI * radius * (radius + height)
Volume = PI * radius * radius * height
L = 2 * PI * radius * height
T = PI * radius * radius

print("\n The Surface area of a Cylinder = %.2f" %sa)
print(" The Volume of a Cylinder = %.2f" %Volume)
print(" Lateral Surface Area of a Cylinder = %.2f" %L);
print(" Top OR Bottom Surface Area of a Cylinder = %.2f" %T)

首先,我們聲明了 PI 變量,并將值賦值為 3.14。以下語句將要求用戶輸入半徑和高度值,并將用戶輸入值分配給相關(guān)變量。例如第一個值將分配給半徑,第二個值分配給高度

radius = float(input('Please Enter the Radius of a Cylinder: '))
height = float(input('Please Enter the Height of a Cylinder: '))

接下來,我們將使用它們各自的公式計算圓柱體的體積、表面積、側(cè)面表面積、頂部或底部表面積:

sa = 2 * PI * radius * (radius + height)
Volume = PI * radius * radius * height
L = 2 * PI * radius * height
T = PI * radius * radius

遵循 Python 打印語句將幫助我們打印圓柱體的體積和表面積

print("\n The Surface area of a Cylinder = %.2f" %sa)
print(" The Volume of a Cylinder = %.2f" %Volume)
print(" Lateral Surface Area of a Cylinder = %.2f" %L);
print(" Top OR Bottom Surface Area of a Cylinder = %.2f" %T)

在這個尋找圓柱體體積和表面積的 Python 程序中,我們輸入了圓柱體的半徑= 3,高度= 5

圓柱體的表面積為

圓柱體的表面積= 2πr + 2πrh

也可以寫成

圓柱體表面積= 2πr (r+h) 圓柱體表面積= 2 PI 半徑(半徑+高度) 圓柱體表面積= 2 3.14 3 (3+5); 圓柱體的表面積= 150.72

圓柱體的體積是

圓柱體的體積= πr h 圓柱體的體積=π半徑半徑高度 圓柱體的體積= 3.14 3 3 5 圓柱體的體積= 141.3

圓柱體的側(cè)面面積為

l = 2rh l = 2 pi radius height l = 2 3.14 3 5 l = 94.2t5

圓柱體的頂面或底面面積為

T =πr T =π半徑半徑 T = 3.14 3 3 T = 28.26

注:為了計算的目的,我們?nèi)ˇ?= 3.14 而不是(3.142857142..).因此,以上所有值幾乎等于程序輸出,但可能相差 0.01。

用函數(shù)求圓柱體體積和表面積的 Python 程序

這個 python 程序允許用戶輸入半徑和高度的值。我們將半徑值傳遞給函數(shù)參數(shù),然后它將根據(jù)公式計算圓柱體的體積、圓柱體的表面積、圓柱體的側(cè)面表面積、圓柱體的頂部或底部表面積。

# Python Program to find Volume & Surface Area of a Cylinder using Functions

import math

def Vol_Sa_Cylinder(radius, height):
    sa = 2 * math.pi * radius * (radius + height)
    Volume = math.pi * radius * radius * height
    L = 2 * math.pi * radius * height
    T = math.pi * radius * radius

    print("\n The Surface area of a Cylinder = %.2f" %sa)
    print(" The Volume of a Cylinder = %.2f" %Volume)
    print(" Lateral Surface Area of a Cylinder = %.2f" %L)
    print(" Top OR Bottom Surface Area of a Cylinder = %.2f" %T)

Vol_Sa_Cylinder(6, 4)

Python 圓柱體輸出的體積和表面積

 The Surface area of a Cylinder = 376.99
 The Volume of a Cylinder = 452.39
 Lateral Surface Area of a Cylinder = 150.80
 Top OR Bottom Surface Area of a Cylinder = 113.10
>>> Vol_Sa_Cylinder(3, 5)

 The Surface area of a Cylinder = 150.80
 The Volume of a Cylinder = 141.37
 Lateral Surface Area of a Cylinder = 94.25
 Top OR Bottom Surface Area of a Cylinder = 28.27
>>> 

首先,我們使用以下語句導(dǎo)入了數(shù)學(xué)庫。這將允許我們使用數(shù)學(xué)函數(shù),如數(shù)學(xué)π。如果你沒有包括這一行,那么數(shù)學(xué)π將通過一個錯誤。

import math

步驟 2:我們使用 def 關(guān)鍵字定義了帶有兩個參數(shù)的函數(shù)。這意味著,用戶將輸入圓柱體的半徑和高度。

步驟 3:我們正在計算圓柱體的體積、表面積、側(cè)面表面積、頂部或底部表面積,正如我們在第一個例子中所解釋的

注意:我們可以用中的參數(shù)調(diào)用函數(shù)?;蛘呶覀兛梢詮?python shell 中調(diào)用它。請不要忘記函數(shù)參數(shù)


文章名稱:Python程序:計算圓柱體體積和表面積
URL地址:http://www.5511xx.com/article/cojcohe.html