Python程序:计算长度和宽度查找矩形面积

创新互联Python教程:

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

用一个实际例子编写 Python 程序,利用长度和宽度找到矩形的面积。

使用长度和宽度查找矩形面积的 Python 程序示例 1

这个 Python 程序允许用户输入矩形的长度和宽度。使用这两个值,它可以找到矩形的面积。如果我们知道矩形的长度和宽度。计算矩形面积的数学公式是:面积=长度*宽度。

# Python Program to find Area of a Rectangle using length and width

length = float(input('Please Enter the Length of a Triangle: '))
width = float(input('Please Enter the Width of a Triangle: '))

# calculate the area
area = length * width

print("The Area of a Rectangle using", length, "and", width, " = ", area)

使用长度和宽度计算矩形面积的 Python 程序示例 2

这个 Python 代码查找矩形的面积同上。然而,我们使用函数的概念分离了 python 程序的逻辑。

# Python Program to find Area of a Rectangle using length and width

def area_of_Rectangle(length, width):
    return length * width
length = float(input('Please Enter the Length of a Triangle: '))
width = float(input('Please Enter the Width of a Triangle: '))

# calculate the area of a Rectangle
area = area_of_Rectangle(length, width)

print("The Area of a Rectangle using", length, "and", width, " = ", area)
Please Enter the Length of a Triangle: 125
Please Enter the Width of a Triangle: 65
The Area of a Rectangle using 125.0 and 65.0  =  8125.0

新闻标题:Python程序:计算长度和宽度查找矩形面积
网页路径:http://www.hxwzsj.com/article/cdoccpg.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 成都网站制作 网站建设公司 四川成都网站建设 网站建设 营销网站建设 成都响应式网站建设 泸州网站建设 成都网站建设公司 成都网站制作 成都网站设计 网站制作公司 企业网站建设 手机网站制作 网站设计 成都网站制作 成都定制网站建设 定制网站设计 成都企业网站制作 温江网站设计 网站建设费用 网站建设公司 网站制作