Python 程序:使用底部和高度计算三角形面积

创新互联python教程:

为玉门等地区用户提供了全套网页设计制作服务,及玉门网站建设行业解决方案。主营业务为网站设计制作、成都网站设计、玉门网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

用一个实际例子编写 Python 程序,用底和高来求三角形的面积。

使用底部和高度查找三角形面积的 Python 程序示例 1

这个 Python 程序允许用户输入三角形的底部和高度。通过使用底部和高度值,它可以找到三角形的面积。用底和高求三角形面积的数学公式:面积=(底*高)/ 2。

# Python Program to find Area of a Triangle using base and height

base = float(input('Please Enter the Base of a Triangle: '))
height = float(input('Please Enter the Height of a Triangle: '))

# calculate the area
area = (base * height) / 2

print("The Area of a Triangle using", base, "and", height, " = ", area)

使用底部和高度计算三角形面积的 Python 程序示例 2

这个 Python 程序对于三角形的面积和上面一样。然而,我们使用 Python 函数概念分离了三角形的面积程序逻辑。

# Python Program to find Area of a Triangle using base and height
def area_of_triangle(base, height):
    return (base * height) / 2

base = float(input('Please Enter the Base of a Triangle: '))
height = float(input('Please Enter the Height of a Triangle: '))

# calculate the area
area = area_of_triangle(base, height)
print("The Area of a Triangle using", base, "and", height, " = ", area)

使用底部和高度输出的三角形的 Python 面积

Please Enter the Base of a Triangle: 35
Please Enter the Height of a Triangle: 85
The Area of a Triangle using 35.0 and 85.0  =  1487.5

网站名称:Python 程序:使用底部和高度计算三角形面积
网站地址:http://www.hantingmc.com/qtweb/news9/501259.html

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

广告

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