新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:計(jì)算長度和寬度查找矩形面積
創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)公司是一家專業(yè)提供平房企業(yè)網(wǎng)站建設(shè),專注與做網(wǎng)站、成都網(wǎng)站制作、成都h5網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為平房眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
用一個實(shí)際例子編寫 Python 程序,利用長度和寬度找到矩形的面積。
使用長度和寬度查找矩形面積的 Python 程序示例 1
這個 Python 程序允許用戶輸入矩形的長度和寬度。使用這兩個值,它可以找到矩形的面積。如果我們知道矩形的長度和寬度。計(jì)算矩形面積的數(shù)學(xué)公式是:面積=長度*寬度。
# 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)使用長度和寬度計(jì)算矩形面積的 Python 程序示例 2
這個 Python 代碼查找矩形的面積同上。然而,我們使用函數(shù)的概念分離了 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程序:計(jì)算長度和寬度查找矩形面積
當(dāng)前URL:http://www.dlmjj.cn/article/cdoccpg.html


咨詢
建站咨詢
