首页 > 编程知识 正文

Python 程序:计算圆形面积

时间:2023-11-25 09:12:54 阅读:309003 作者:MLCY

写一个 python 程序,利用半径、环境和直径来找到圆的面积。圆的 Python 面积是圆内的平方单位数。计算圆面积的标准公式是: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 程序允许用户输入半径值。然后,它会根据公式计算圆的面积。一个圆的 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

首先,我们导入了数学库,这支持我们使用 Python 编程中的所有数学函数。在这个 Python 的例子中,我们可以使用 math.pi 来调用 PI 值

import math

python 程序的下一行允许用户输入周长值。

circumference = float(input(' Please Enter the Circumference of a circle: '))

利用周长,本程序将按照公式计算圆的面积: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)

圆程序的这个面积允许用户输入直径值。接下来,它将根据我们上面显示的公式计算圆的面积。

我们还提到了其他方法。

直径= 2 *半径

半径=直径/2

面积= π 半径半径

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。