日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python 程序:計算梯形面積

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

如何用例子編寫 Python 程序求梯形面積和梯形中值?在我們進入實際的 Python 程序尋找梯形面積的例子之前,讓我們看看定義和公式

梯形的 Python 面積

如果我們知道高度和兩個底長,那么我們可以用下面的公式計算梯形的面積:

面積= (a+b)/2 * h

其中 a 和 b 是兩個底,h 是梯形的高度。我們可以用下面的公式計算梯形的中值:

中位數(shù)= (a+b) / 2。

如果我們知道中間值和高度,那么我們可以計算梯形的面積為:中間值*高度

尋找梯形面積的 Python 程序

這個 python 程序允許用戶輸入梯形的兩邊和高度。使用這些值,這個 Python 程序將計算梯形的面積和梯形的中值。

# Python Program to find Area of a Trapezoid

base1 = float(input('Please Enter the First Base of a Trapezoid: '))
base2 = float(input('Please Enter the Second Base of a Trapezoid: '))
height = float(input('Please Enter the Height of a Trapezoid: '))

# calculate the area
Area = 0.5 * (base1 + base2) * height

# calculate the Median
Median = 0.5 * (base1+ base2)

print("\n Area of a Trapezium = %.2f " %Area)
print(" Median of a Trapezium = %.2f " %Median)

以下語句將要求用戶輸入 base1、base2 和 height 值,并將用戶輸入值分配給相關變量。如第一個值將賦給 base1,第二個值賦給 base2,第三個值賦給高度

base1 = float(input('Please Enter the First Base of a Trapezoid: '))
base2 = float(input('Please Enter the Second Base of a Trapezoid: '))
height = float(input('Please Enter the Height of a Trapezoid: '))

接下來,我們使用它們各自的公式計算梯形的中值和面積:

# calculate the area
Area = 0.5 * (base1 + base2) * height

# calculate the Median
Median = 0.5 * (base1+ base2)

打印語句將幫助我們打印梯形的中值和面積

print("\n Area of a Trapezium = %.2f " %Area)
print(" Median of a Trapezium = %.2f " %Median)

讓我們看看程序的輸出

Please Enter the First Base of a Trapezoid: 6
Please Enter the Second Base of a Trapezoid: 9
Please Enter the Height of a Trapezoid: 4

 Area of a Trapezium = 30.00 
 Median of a Trapezium = 7.50

從上面的 Python 截圖可以觀察到,我們輸入的值是 base1 = 6,base2 = 9,height = 4

梯形的面積= 0.5 (基底 1 +基底 2)高度; 梯形的面積= 0.5 (6+9) 4; 梯形的面積= 0.5 15 4; 梯形面積= 30

梯形的中值= 0.5 (base 1+base 2); 梯形的中值= 0.5 (6 + 9) 梯形的中值= 0.5 * 15 梯形的中值= 7.5

用函數(shù)求梯形面積的 Python 程序

這個 python 程序允許用戶輸入梯形的基底 1、基底 2 和高度。我們將把這些值傳遞給函數(shù)參數(shù)來計算梯形的面積。

# Python Program to find Area of a Trapezoid using Functions

def Area_of_a_Trapezoid (base1, base2, height):
    # calculate the area
    Area = 0.5 * (base1 + base2) * height

    # calculate the Median
    Median = 0.5 * (base1+ base2)

    print("\n Area of a Trapezium = %.2f " %Area)
    print(" Median of a Trapezium = %.2f " %Median)

Area_of_a_Trapezoid (9, 6, 4)

在這個尋找梯形面積的 Python 程序示例中,首先,我們使用 def 關鍵字定義了具有三個參數(shù)的函數(shù)。這意味著,用戶將輸入梯形的底 1、底 2 和高度。接下來,我們計算梯形的中值和面積,正如我們在第一個例子中所描述的。

注意:我們可以用中的參數(shù)調用函數(shù)?;蛘呶覀兛梢詮?python shell 中調用它。請不要忘記函數(shù)參數(shù)


當前標題:Python 程序:計算梯形面積
瀏覽路徑:http://m.5511xx.com/article/dhgpooc.html