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

創(chuàng)新互聯(lián)公司是一家專業(yè)提供安平企業(yè)網(wǎng)站建設,專注與網(wǎng)站制作、做網(wǎng)站、H5頁面制作、小程序制作等業(yè)務。10年已為安平眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡公司優(yōu)惠進行中。
寫一個 python 程序,利用半徑、環(huán)境和直徑來找到圓的面積。圓的 Python 面積是圓內(nèi)的平方單位數(shù)。計算圓面積的標準公式是:A=πr。
用半徑求圓面積的 Python 程序
如果我們知道半徑,那么我們可以用公式計算圓的面積:A=πr(這里 A 是圓的面積,r 是半徑)。在這個 python 程序中,我們將使用半徑找到圓的面積。
# Python Program to find Area Of Circle using Radius
PI = 3.14
radius = float(input(' Please Enter the radius of a circle: '))
area = PI * radius * radius
circumference = 2 * PI * radius
print(" Area Of a Circle = %.2f" %area)
print(" Circumference Of a Circle = %.2f" %circumference)我們將 pi 定義為全局變量,賦值為 3.14。這個 python 程序允許用戶輸入半徑值。然后,它會根據(jù)公式計算圓的面積。一個圓的 Python 面積的輸出是
Please Enter the radius of a circle: 6
Area Of a Circle = 113.04
Circumference Of a Circle = 37.68
用圓周求圓面積的 Python 程序
繞圓的距離稱為周長。如果你知道周長,那么我們可以用公式計算圓的面積:A = C4π(這里 C 是周長)
import math
circumference = float(input(' Please Enter the Circumference of a circle: '))
area = (circumference * circumference)/(4 * math.pi)
print(" Area Of a Circle = %.2f" %area)Python 面積的一個圓使用圓周輸出
Please Enter the Circumference of a circle: 26
Area Of a Circle = 53.79首先,我們導入了數(shù)學庫,這支持我們使用 Python 編程中的所有數(shù)學函數(shù)。在這個 Python 的例子中,我們可以使用 math.pi 來調(diào)用 PI 值
import mathpython 程序的下一行允許用戶輸入周長值。
circumference = float(input(' Please Enter the Circumference of a circle: '))利用周長,本程序?qū)凑展接嬎銏A的面積:A = C‖4π
用直徑計算圓面積的 Python 程序
穿過圓心的距離稱為直徑。如果我們知道直徑,那么我們可以用公式計算圓的面積:A=π/4*D (D 是直徑)
import math
diameter = float(input(' Please Enter the Diameter of a circle: '))
area1 = (math.pi/4) * (diameter * diameter)
# diameter = 2 * radius
# radius = diameter/2
radius = diameter / 2
area2 = math.pi * radius * radius
print(" Area of Circle using direct formula = %.2f" %area1);
print(" Area of Circle Using Method 2 = %.2f" %area2)圓程序的這個面積允許用戶輸入直徑值。接下來,它將根據(jù)我們上面顯示的公式計算圓的面積。
我們還提到了其他方法。
直徑= 2 *半徑
半徑=直徑/2
面積= π 半徑半徑
分享名稱:Python程序:計算圓形面積
文章網(wǎng)址:http://www.5511xx.com/article/cocsesp.html


咨詢
建站咨詢
