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

創(chuàng)新互聯(lián)是一家成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè),提供網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,網(wǎng)站制作,建網(wǎng)站,按需求定制設(shè)計,網(wǎng)站開發(fā)公司,于2013年成立是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價值為核心業(yè)務(wù),全程參與項目的網(wǎng)站策劃設(shè)計制作,前端開發(fā),后臺程序制作以及后期項目運營并提出專業(yè)建議和思路。
編寫 Python 程序,通過一個實際例子,利用長度和寬度找到矩形的周長。
使用長度和寬度查找矩形周長的 Python 程序示例 1
這個 Python 程序允許用戶輸入矩形的長度和寬度。通過使用長度和寬度,這個程序找到一個矩形的周長。計算矩形周長的數(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
使用長度和寬度計算矩形周長的 Python 程序示例 2
這個 Python 程序求矩形周長同上。但是,在這個 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)頁題目:Python程序:利用長度和寬度計算矩形周長
本文路徑:http://m.5511xx.com/article/dpdjhjc.html


咨詢
建站咨詢
