Python程序:计算圆形面积

创新互联python教程:

创新互联公司是一家专业提供安平企业网站建设,专注与网站制作、做网站、H5页面制作、小程序制作等业务。10年已为安平众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

写一个 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

面积= π 半径半径

网站题目:Python程序:计算圆形面积
本文链接:http://www.mswzjz.com/qtweb/news38/177888.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联