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

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

新聞中心

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

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

用例子寫一個 Python 程序來尋找直角三角形的面積。在我們進(jìn)入 Python 程序?qū)ふ抑苯侨切蔚拿娣e之前,讓我們看看定義和公式

直角三角形的 Python 面積

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

面積= (1/2) 寬度高度

利用畢達(dá)哥拉斯公式,我們可以很容易地找到直角三角形中未知的邊。

c = a + b

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

周長= a + b+ c

尋找直角三角形面積的 Python 程序

這個 python 程序允許用戶輸入直角三角形的寬度和高度。使用這些值,我們將計算直角三角形的面積和周長。

# Python Program to find Area of a Right Angled Triangle
import math

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

# calculate the area
Area = 0.5 * width * height

# calculate the Third Side
c = math.sqrt((width*width) + (height*height))

# calculate the Perimeter
Perimeter = width + height + c

print("\n Area of a right angled triangle is: %.2f" %Area)
print(" Other side of right angled triangle is: %.2f" %c)
print(" Perimeter of right angled triangle is: %.2f" %Perimeter)

直角三角形輸出的 Python 面積

Please Enter the Width of a Right Angled Triangle: 7
Please Enter the Height of a Right Angled Triangle: 8

 Area of a right angled triangle is: 28.00
 Other side of right angled triangle is: 10.63
 Perimeter of right angled triangle is: 25.63

首先,我們使用以下語句導(dǎo)入了數(shù)學(xué)庫。這將允許我們使用數(shù)學(xué)函數(shù),如 math.sqrt 函數(shù)

import math

遵循 Python 語句將允許用戶輸入直角三角形的寬度和高度。

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

接下來,我們計算面積(1/2 = 0.5 的值)。所以我們用 0.5 高作為公式

Area = 0.5 * width * height

在下一行中,我們使用畢達(dá)哥拉斯公式 C =a +b 計算直角三角形的另一邊,類似于 C = √a +b

c = math.sqrt((width*width) + (height*height))

這里我們用 sqrt()函數(shù)計算 a +b 的平方根,sqrt()是數(shù)學(xué)函數(shù),用來計算平方根。

在下一行,我們使用公式計算周長

Perimeter = width + height + c

以下打印語句將幫助我們打印直角三角形的周長、其他邊和面積

print("\n Area of a right angled triangle is: %.2f" %Area)
print(" Other side of right angled triangle is: %.2f" %c)
print(" Perimeter of right angled triangle is: %.2f" %Perimeter)

用函數(shù)求直角三角形面積的 Python 程序

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

# Python Program to find Area of a Right Angled Triangle using Functions

import math

def Area_of_a_Right_Angled_Triangle(width, height):
    # calculate the area
    Area = 0.5 * width * height

    # calculate the Third Side
    c = math.sqrt((width * width) + (height * height))
    # calculate the Perimeter
    Perimeter = width + height + c

    print("\n Area of a right angled triangle is: %.2f" %Area)
    print(" Other side of right angled triangle is: %.2f" %c)
    print(" Perimeter of right angled triangle is: %.2f" %Perimeter)

Area_of_a_Right_Angled_Triangle(9, 10)

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


當(dāng)前標(biāo)題:Python程序:計算直角三角形面積
轉(zhuǎn)載源于:http://m.5511xx.com/article/dpicdgh.html