av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python程序:計算矩形面積

創(chuàng)新互聯(lián)python教程:

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:主機域名、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、南陽網(wǎng)站維護、網(wǎng)站推廣。

用例子寫一個 Python 程序來尋找矩形的面積和周長。在我們進入 Python 程序?qū)ふ揖匦蚊娣e的例子之前,讓我們看看定義和公式。

矩形的 Python 面積

如果我們知道寬度和高度,我們就可以用下面的公式計算矩形的面積。

面積=寬度*高度

周長是邊緣周圍的距離。我們可以用下面的公式計算矩形的周長

周長= 2 *(寬度+高度)

尋找矩形面積和矩形周長的 Python 程序

這個矩形面積程序允許用戶輸入矩形的寬度和高度。使用這些值,這個 python 程序?qū)⒂嬎憔匦蔚拿娣e和周長。

# Python Program to find Area of a Rectangle

width = float(input('Please Enter the Width of a Rectangle: '))
height = float(input('Please Enter the Height of a Rectangle: '))

# calculate the area
Area = width * height

# calculate the Perimeter
Perimeter = 2 * (width + height)

print("\n Area of a Rectangle is: %.2f" %Area)
print(" Perimeter of Rectangle is: %.2f" %Perimeter)

以下語句將允許用戶輸入矩形的寬度和高度。

width = float(input('Please Enter the Width of a Rectangle: '))
height = float(input('Please Enter the Height of a Rectangle: '))

接下來,我們按照公式 計算面積

Area = width * height

在下一條 Python 線中,我們正在計算矩形的周長

Perimeter = 2 * (width + height)

以下打印語句將幫助我們打印矩形的周長和面積

print("\n Area of a Rectangle is: %.2f" %Area)
print(" Perimeter of Rectangle is: %.2f" %Perimeter)

使用函數(shù)尋找矩形面積的 Python 程序

這個 Python 面積的矩形程序允許用戶輸入矩形的寬度和高度。我們將把這些值傳遞給函數(shù)參數(shù)來計算矩形的面積。

# Python Program to find Area of a Rectangle using Functions

def Area_of_a_Rectangle(width, height):

    # calculate the area
    Area = width * height

    # calculate the Perimeter
    Perimeter = 2 * (width + height)

    print("\n Area of a Rectangle is: %.2f" %Area)
    print(" Perimeter of Rectangle is: %.2f" %Perimeter)

Area_of_a_Rectangle(6, 4)

在矩形程序的這個面積內(nèi),首先,我們使用 def 關(guān)鍵字定義了帶有兩個參數(shù)的函數(shù)。這意味著,用戶將輸入矩形的寬度和高度。接下來,我們計算一個矩形的周長和面積,就像我們在第一個例子中描述的那樣。

 Area of a Rectangle is: 24.00
 Perimeter of Rectangle is: 20.00
>>> Area_of_a_Rectangle(12, 9)

 Area of a Rectangle is: 108.00
 Perimeter of Rectangle is: 42.00
>>> 

分享名稱:Python程序:計算矩形面積
分享網(wǎng)址:http://uogjgqi.cn/article/dheggjc.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流