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

成都創(chuàng)新互聯(lián)公司是一家網(wǎng)站建設(shè)、成都做網(wǎng)站,提供網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,網(wǎng)站制作,建網(wǎng)站,按需策劃,網(wǎng)站開發(fā)公司,從2013年成立是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價值為核心業(yè)務(wù),全程參與項目的網(wǎng)站策劃設(shè)計制作,前端開發(fā),后臺程序制作以及后期項目運營并提出專業(yè)建議和思路。
如何用例子編寫 Python 程序求球體的體積和表面積?在我們進(jìn)入 Python 程序?qū)ふ仪蝮w的體積和表面積之前,讓我們看看定義和公式
球體的 Python 表面積
球體看起來像一個籃球,或者我們可以說是一個圓的三維視圖。如果我們知道球體的半徑,那么我們可以用公式計算球體的表面積:
球體的表面積= 4πr(其中 r 是球體的半徑)。
根據(jù)上面的公式,如果我們知道球體的表面積,那么我們可以使用以下公式計算球體的半徑:
球面半徑= √sa / 4π(其中 sa 是球面的表面積)。
球體的 Python 體積
球體內(nèi)部的空間量稱為體積。如果我們知道球體的半徑,那么我們可以用公式計算球體的體積:
球體的體積= 4πr
尋找球體體積和表面積的 Python 程序
我們將 pi 定義為全局變量,賦值為 3.14。這個 python 程序允許用戶輸入半徑值,然后根據(jù)公式計算球體的表面積和體積。
# Python Program to find Volume and Surface Area of Sphere
PI = 3.14
radius = float(input('Please Enter the Radius of a Sphere: '))
sa = 4 * PI * radius * radius
Volume = (4 / 3) * PI * radius * radius * radius
print("\n The Surface area of a Sphere = %.2f" %sa)
print("\n The Volume of a Sphere = %.2f" %Volume)
在這個尋找球體體積和表面積的 Python 程序中,我們輸入了球體半徑= 5
球體的表面積是
表面積= 4πr 表面積= 4 π半徑半徑; 表面積= 4 3.14 5 5 表面積= 314
球體的體積是
體積= 4πr 體積=(4.0/3)π半徑半徑半徑; 體積=(4.0/3) 3.14 5 5 5; 卷= 523.33333
讓我們用表面積來計算球體的半徑:
在上面的 Python 示例中,當(dāng)半徑= 5 時,我們得到了球體的表面積= 314。讓我們做相反的方法(從表面積計算半徑= 5)
球體半徑= √sa / 4π 球體半徑= √314 / 4 * 3.14 球體半徑= √314 / 12.56 球體半徑= √25 球體半徑= 5
用函數(shù)求球體體積和表面積的 Python 程序
這個 python 程序允許用戶輸入半徑值。我們將半徑值傳遞給函數(shù)參數(shù),然后它將根據(jù)公式計算球體的表面積和體積。
# Python Program to find Volume and Surface Area of Sphere using Functions
import math
def Area_of_Triangle(radius):
sa = 4 * math.pi * radius * radius
Volume = (4 / 3) * math.pi * radius * radius * radius
print("\n The Surface area of a Sphere = %.2f" %sa)
print("\n The Volume of a Sphere = %.2f" %Volume)
Area_of_Triangle(6)球體輸出的 Python 表面積和體積
The Surface area of a Sphere = 452.39
The Volume of a Sphere = 904.78
>>> Area_of_Triangle(11)
The Surface area of a Sphere = 1520.53
The Volume of a Sphere = 5575.28
>>> 在這個尋找球體體積和表面積的 Python 程序中,首先,我們使用以下語句導(dǎo)入了數(shù)學(xué)庫。這將允許我們使用數(shù)學(xué)函數(shù),比如 math.pi
import math第二步:接下來,我們使用 def 關(guān)鍵字用一個參數(shù)定義函數(shù)。這意味著,用戶將輸入一個球體的半徑。
第三步:根據(jù)公式計算球體的表面積和體積
注意:在放置開括號和閉括號時請小心,如果放置錯誤,可能會改變整個計算
網(wǎng)站題目:Python程序:計算球體體積和表面積
文章起源:http://www.5511xx.com/article/coopose.html


咨詢
建站咨詢
