新聞中心
創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)是一家成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè),提供網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),網(wǎng)站制作,建網(wǎng)站,按需求定制設(shè)計(jì),網(wǎng)站開發(fā)公司,于2013年成立是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價(jià)值為核心業(yè)務(wù),全程參與項(xiàng)目的網(wǎng)站策劃設(shè)計(jì)制作,前端開發(fā),后臺(tái)程序制作以及后期項(xiàng)目運(yùn)營并提出專業(yè)建議和思路。
編寫 Python 程序,通過一個(gè)實(shí)際例子,利用長度和寬度找到矩形的周長。
使用長度和寬度查找矩形周長的 Python 程序示例 1
這個(gè) Python 程序允許用戶輸入矩形的長度和寬度。通過使用長度和寬度,這個(gè)程序找到一個(gè)矩形的周長。計(jì)算矩形周長的數(shù)學(xué)公式:周長= 2 *(長度+寬度)。如果我們知道長度和寬度。
# Python Program to find Perimeter 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 perimeter
perimeter = 2 * (length + width)
print("Perimeter of a Rectangle using", length, "and", width, " = ", perimeter)
Please Enter the Length of a Triangle: 35
Please Enter the Width of a Triangle: 88
Perimeter of a Rectangle using 35.0 and 88.0 = 246.0
使用長度和寬度計(jì)算矩形周長的 Python 程序示例 2
這個(gè) Python 程序求矩形周長同上。但是,在這個(gè) python 程序中,我們使用 Python 函數(shù)來分隔矩形邏輯的周長。
# Python Program to find Perimeter of a Rectangle using length and width
def perimeter_of_Rectangle(length, width):
return 2 * (length + width)
length = float(input('Please Enter the Length of a Triangle: '))
width = float(input('Please Enter the Width of a Triangle: '))
# calculate the perimeter
perimeter = perimeter_of_Rectangle(length, width)
print("Perimeter of a Rectangle using", length, "and", width, " = ", perimeter) 網(wǎng)站標(biāo)題:Python程序:利用長度和寬度計(jì)算矩形周長
文章出自:http://www.dlmjj.cn/article/dpdjhjc.html


咨詢
建站咨詢
