新聞中心
創(chuàng)新互聯(lián)python教程:

目前創(chuàng)新互聯(lián)建站已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、鎮(zhèn)江網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
如何用例子編寫 Python 程序求長(zhǎng)方體的體積和表面積?在我們進(jìn)入 Python 程序?qū)ふ议L(zhǎng)方體的體積和表面積之前,讓我們看看長(zhǎng)方體的頂面和底面表面積、側(cè)面表面積后面的定義和公式
Python 長(zhǎng)方體
長(zhǎng)方體是由 6 個(gè)矩形組成的三維物體。所有相對(duì)的面(即頂部和底部)都是相等的。
長(zhǎng)方體的表面積
長(zhǎng)方體的總表面積是長(zhǎng)方體中所有 6 個(gè)矩形面積的總和。如果我們知道長(zhǎng)方體的長(zhǎng)度、寬度和高度,那么我們可以使用以下公式計(jì)算總表面積:
頂面和底面面積= lw+lw = 2w
前后表面面積= lh + lh = 2lh
兩側(cè)面積= wh + wh = 2wh
長(zhǎng)方體的總表面積是所有 6 個(gè)面的總和。因此,我們必須將所有這些面積相加,以計(jì)算最終的表面積
長(zhǎng)方體的總表面積= 2lw + 2lh + 2wh
相等:總表面積= 2 (lw + lh +wh)
長(zhǎng)方體的體積
長(zhǎng)方體內(nèi)部的空間量叫做體積。如果我們知道長(zhǎng)方體的長(zhǎng)度、寬度和高度,那么我們可以用下面的公式計(jì)算體積:
長(zhǎng)方體的體積=長(zhǎng)寬高
長(zhǎng)方體的體積=磅
長(zhǎng)方體的側(cè)面面積= 2h (l + w)
Python 程序求長(zhǎng)方體的體積和表面積
這個(gè) Python 程序允許用戶輸入長(zhǎng)方體的長(zhǎng)度、寬度和高度。利用這些值,編譯器將根據(jù)公式計(jì)算長(zhǎng)方體的表面積、體積和側(cè)面面積。
# Python Program to find Volume and Surface Area of Cuboid
length = float(input('Please Enter the Length of a Cuboid: '))
width = float(input('Please Enter the Width of a Cuboid: '))
height = float(input('Please Enter the Height of a Cuboid: '))
# Calculate the Surface Area
SA = 2 * (length * width + length * height + width * height)
# Calculate the Volume
Volume = length * width * height
# Calculate the Lateral Surface Area
LSA = 2 * height * (length + width)
print("\n The Surface Area of a Cuboid = %.2f " %SA)
print(" The Volume of a Cuboid = %.2f" %Volume);
print(" The Lateral Surface Area of a Cuboid = %.2f " %LSA)下面的語(yǔ)句將要求用戶輸入長(zhǎng)度、寬度和高度值,并將用戶輸入值分配給相應(yīng)的變量。例如第一個(gè)值將分配給長(zhǎng)度,第二個(gè)值分配給寬度,第三個(gè)值分配給高度
length = float(input('Please Enter the Length of a Cuboid: '))
width = float(input('Please Enter the Width of a Cuboid: '))
height = float(input('Please Enter the Height of a Cuboid: '))接下來(lái),我們將使用長(zhǎng)方體的體積、表面積和側(cè)表面積各自的公式來(lái)計(jì)算它們:
# Calculate the Surface Area
SA = 2 * (length * width + length * height + width * height)
# Calculate the Volume
Volume = length * width * height
# Calculate the Lateral Surface Area
LSA = 2 * height * (length + width)遵循 Python 打印語(yǔ)句將幫助我們打印長(zhǎng)方體的體積和表面積
print("\n The Surface Area of a Cuboid = %.2f " %SA)
print(" The Volume of a Cuboid = %.2f" %Volume);
print(" The Lateral Surface Area of a Cuboid = %.2f " %LSA)
在上面的 Python 程序中查找長(zhǎng)方體的體積和表面積的例子中,我們插入了長(zhǎng)度= 8,寬度= 5 和高度= 6 的值
給定度量的長(zhǎng)方體體積為:
長(zhǎng)方體的體積= lbh = l w h 長(zhǎng)方體的體積=長(zhǎng)寬高 長(zhǎng)方體的體積= 8 5 6 長(zhǎng)方體的體積= 240
長(zhǎng)方體的體積是 240
對(duì)于給定的度量,長(zhǎng)方體的總表面積為:
長(zhǎng)方體總表面積= 2lw + 2lh + 2wh 長(zhǎng)方體總表面積= 2 (lw + lh +wh) 長(zhǎng)方體總表面積= 2(長(zhǎng)寬+長(zhǎng)高+寬高) 長(zhǎng)方體總表面積= 2 (8 5)+(8 6)+(5 6)) 長(zhǎng)方體總表面積= 2 (40 + 48 + 30) 長(zhǎng)方體總表面積= 2 118 長(zhǎng)方體總表面積= 236
長(zhǎng)方體的總表面積是 236
對(duì)于給定的測(cè)量,長(zhǎng)方體的側(cè)面面積為:
長(zhǎng)方體側(cè)面面積= 2lh + 2wh 長(zhǎng)方體側(cè)面面積= 2h (l + w) 長(zhǎng)方體側(cè)面面積= 2 高(長(zhǎng)+寬) 長(zhǎng)方體側(cè)面面積= 2 6 (8 + 5) 長(zhǎng)方體側(cè)面面積= 2 6 (13 ) 長(zhǎng)方體側(cè)面面積= 156T8】
長(zhǎng)方體的側(cè)面面積是 156
用函數(shù)求長(zhǎng)方體體積和表面積的 Python 程序
這個(gè) python 程序允許用戶輸入長(zhǎng)度、寬度和高度值。我們將這些值傳遞給函數(shù)參數(shù),然后它將根據(jù)公式計(jì)算長(zhǎng)方體的表面積和體積。
# Python Program to find Volume and Surface Area of a Cuboid using Functions
def Vo_Sa_Cuboid(length, width, height):
# Calculate the Surface Area
SA = 2 * (length * width + length * height + width * height)
# Calculate the Volume
Volume = length * width * height
# Calculate the Lateral Surface Area
LSA = 2 * height * (length + width)
print("\n The Surface Area of a Cuboid = %.2f " %SA)
print(" The Volume of a Cuboid = %.2f" %Volume)
print(" The Lateral Surface Area of a Cuboid = %.2f " %LSA)
Vo_Sa_Cuboid(9, 4, 6)我們使用 def 關(guān)鍵字用三個(gè)參數(shù)定義了這個(gè)函數(shù)。這意味著,用戶將輸入長(zhǎng)方體的長(zhǎng)度、寬度和高度值。這個(gè) Python 程序?qū)⒂?jì)算長(zhǎng)方體的表面積和體積,就像我們?cè)诘谝粋€(gè)例子 中解釋的那樣
The Surface Area of a Cuboid = 228.00
The Volume of a Cuboid = 216.00
The Lateral Surface Area of a Cuboid = 156.00
>>> Vo_Sa_Cuboid(8, 5, 6)
The Surface Area of a Cuboid = 236.00
The Volume of a Cuboid = 240.00
The Lateral Surface Area of a Cuboid = 156.00
>>> 注意:我們可以用中的參數(shù)調(diào)用函數(shù)?;蛘呶覀兛梢詮?python shell 中調(diào)用它。請(qǐng)不要忘記函數(shù)參數(shù)
新聞標(biāo)題:Python程序:求長(zhǎng)方體的體積和表面積
文章網(wǎng)址:http://www.dlmjj.cn/article/coshgop.html


咨詢
建站咨詢
